第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 BeautifulSoup 從特定 <div> 中特定 <h3> 之后的 <ol> 中提取文本

使用 BeautifulSoup 從特定 <div> 中特定 <h3> 之后的 <ol> 中提取文本

泛舟湖上清波郎朗 2023-08-21 19:23:12
我正在嘗試使用 BeautifulSoup 從此頁面中的某個(gè)“ol”中提取文本。我想要獲取的信息位于具有特定類的特定“div”下,但我希望列表項(xiàng)中的文本立即出現(xiàn)在某個(gè)“h3”之后,其中包含帶有類和 id 的“span”??磮D:輸出應(yīng)該是:Verb1. (transitive) To join or unite (e.g. one thing to another, or as several particulars) so as to increase the number, augment the quantity or enlarge the magnitude, or so as to form into one aggregate.2. To sum up; to put together mentally....到目前為止我所做的是:from bs4 import BeautifulSoupimport urlliburl = urllib.urlopen('https://en.wiktionary.org/wiki/add#English')content = url.read()soup = BeautifulSoup(content, 'lxml')main_div = soup.findAll('div',attrs={"class":"mw-parser-output"})for x in main_div:    all_h3 = x.findAll('h3')    all_ol = x.findAll('ol')這個(gè)問題的第一個(gè)答案可能是相關(guān)的,但我不知道如何為我的任務(wù)編輯它。
查看完整描述

1 回答

?
慕娘9325324

TA貢獻(xiàn)1783條經(jīng)驗(yàn) 獲得超4個(gè)贊

lxml.html您可以使用XPath 表達(dá)式來代替 BeautifulSoup 。


Python


import requests

import io

from lxml import html


res = requests.get("https://en.wiktionary.org/wiki/add#English")


tree = html.parse(io.StringIO(res.text))


outputs = []


h3 = tree.xpath("//h3[span[@class = 'mw-headline' and @id = 'Verb']]")[0]


outputs.append(h3.xpath("span")[0].text)


ol = h3.xpath("following::ol[1]")[0]


outputs.append(ol.text_content())


print(outputs)

輸出


['Verb',

 '(transitive) To join or unite (e.g. one thing to another, or as several particulars) so as to increase the number, augment the quantity, or enlarge the magnitude, or so as to form into one aggregate.\nTo sum up; to put together mentally.\n1689, John Locke, An Essay Concerning Human Understanding\n […] as easily as he can add together the ideas of two days or two years.\nto add numbers\n(transitive) To combine elements of (something) into one quantity.\nto add a column of numbers\n(transitive) To give by way of increased possession (to someone); to bestow (on).\n1611, King James Version, Genesis 30:24:\nThe LORD shall add to me another son.\n1667, John Milton, Paradise Lost:\nBack to thy punishment, False fugitive, and to thy speed add wings.\n(transitive) To append (e,g, a statement); to say further information.\n1855, Thomas Babington Macaulay, The History of England from the Accession of James the Second, volume 3, page 37\xa0[1]:\nHe added that he would willingly consent to the entire abolition of the tax\n1900, L. Frank Baum, The Wonderful Wizard of Oz Chapter 23\n"Bless your dear heart," she said, "I am sure I can tell you of a way to get back to Kansas." Then she added, "But, if I do, you must give me the Golden Cap."\n(intransitive) To make an addition; to augment; to increase.\n1611, King James Version, 1 Kings 12:14:\nI will add to your yoke\n2013 June 29,  “A punch in the gut”, in  The Economist, volume 407, number 8842, page 72-3:Mostly, the microbiome is beneficial. […] Research over the past few years, however, has implicated it in diseases from atherosclerosis to asthma to autism. Dr Yoshimoto and his colleagues would like to add liver cancer to that list.\nIt adds to our anxiety.\n(intransitive, mathematics) To perform the arithmetical operation of addition.\nHe adds rapidly.\n(intransitive, video games) To summon minions or reinforcements.\nTypically, a hostile mob will add whenever it\'s within the aggro radius of a player.']



查看完整回答
反對(duì) 回復(fù) 2023-08-21
  • 1 回答
  • 0 關(guān)注
  • 136 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)