问题
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