find specific text in beautifulsoup

。_饼干妹妹 提交于 2020-01-25 17:08:12

问题


I have a specific piece of text i'm trying to get using BeautifulSoup and Python, however I am not sure how to get it using sou.find().

I am trying to obtain "#1 in Beauty" only from the following.

<ul>
<li>...<li>
<li>...<li>
<li id="salesRank">
    <b>Amazon Best Sellers Rank:</b>
    "#1 in Beauty ("
    <a href="http://www.amazon.com/gp/bestsellers/beauty/ref=pd_dp_ts_k_1"> See top 100</a>
    ")

Can anyone help me with this?


回答1:


You need to use the find_all method of soup. Try below

import urllib, urllib2
from bs4 import BeautifulSoup, Comment
url='your url here'
content = urllib2.urlopen(url).read()
soup = BeautifulSoup(content, "html.parser")
print soup.find_all('#1 in Beauty')


来源:https://stackoverflow.com/questions/26183643/find-specific-text-in-beautifulsoup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!