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

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

從標簽中檢索內容

從標簽中檢索內容

九州編程 2021-09-11 10:28:27
在我之前的一篇文章中,我能夠檢索所有 p 標簽import bs4from urllib.request import  urlopen as uReqfrom bs4 import BeautifulSoup as soupmy_url='https://www.centralpark.com/things-to-do/central-park-zoo/polar-bears/'# opening up connectionuClient = uReq(my_url)page_html = uClient.read()# close connectionuClient.close()page_soup = soup(page_html, features="html.parser")ps=list(page_soup.find_all('p'))for s in ps:    print(s)我想要的是檢索這些 p 標簽中的任何內容。前任:ex1='<p> this is example </p>' -> I want res1 = 'this is example' ex2='<p> this is <strong> nice </strong> example </p>' -> I want res2 = 'this is nice example' ex3='<p> this is <b> okeyish </b> example </p>' -> I want res3 = 'this is okeyish example'所有結果(res1,res2,res3)都可以進入List。我已經搜索了解決方案,但建議的解決方案只適用于一種類型的標簽示例。我想要的只是檢索 p 和 /p 之間的所有內容,無論它們之間出現哪些其他標簽。如果那些其他標簽有內容,那些也應該包括在內。
查看完整描述

1 回答

?
紅糖糍粑

TA貢獻1815條經驗 獲得超6個贊

ps=page_soup.find_all('p')


results = []

for s in ps:

    #print(s.text)

    results = results.append(s.text)


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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