亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我想從網站中排除粗體段落

我想從網站中排除粗體段落

神不在的星期二 2021-08-11 17:25:09
我使用以下代碼來抓取網站:import requestsfrom bs4 import BeautifulSoupresp = requests.get('https://www.ecb.europa.eu/press/pressconf/2018/html/ecb.is180913.en.html')soup = BeautifulSoup(resp.content, 'html5lib')article = soup.find('article')paragraphs = article.find_all('p')輸出看起來像:[<p>Based on our regular economic and monetary analyses, we decided to keep the <strong>key ECB interest rates</strong> unchanged. .... to levels that are below, but close to, 2% over the medium term.</p>,<p><strong>Has QE been used well by the various euro area countries?</strong></p>, <p>By and large, yes, it's been used well in the sense that the intended effects of the QE – mind, ... It reduced dispersion in growth rates everywhere. An employment situation which is by and large improving almost everywhere, some countries more than others. </p>, <p>If your question is meant to say; shouldn't governments have taken advantage of the situation of such low rates to decrease budget deficits, to restore? ... is a good situation for doing that.</p>, <p><strong>My second question is on reinvestment. ...Have you today explicitly asked the committees to come up with proposals on reinvestments?</strong></p>, <p>About inflation: I said inflation is going to hover around the present level for the rest of the year and then I gave numbers for next year and 2020. ...will reach our objective over the medium term. </p>,]我想排除包含的粗體段落 <p><strong>我嘗試編碼但未能獲得所需的輸出。如果您能幫助我,我將不勝感激。
查看完整描述

2 回答

?
郎朗坤

TA貢獻1921條經驗 獲得超9個贊

用于str()將 bs4 對象轉換為字符串<p><strong>......</strong></p>


....

paragraphs = article.find_all('p')


for p in paragraphs:

    if '<p><strong>' not in str(p):

        print str(p)


查看完整回答
反對 回復 2021-08-11
?
當年話下

TA貢獻1890條經驗 獲得超9個贊

試試這個extract()功能:

article = soup.find('article')paragraphs = article.find_all('p')article.strong.extract()paragraphs_without_bold = article.find_all('p')

另請參見。


查看完整回答
反對 回復 2021-08-11
  • 2 回答
  • 0 關注
  • 311 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號