2014-10-03 98 views
0

我有一段特定的文本,我試圖使用BeautifulSoup和Python,但是我不知道如何使用sou.find()來獲取它。在beautifulsoup中找到特定文本

我想從下面獲得「#1美容」。

<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> 
    ") 

任何人都可以幫助我嗎?

回答

0

您需要使用soupfind_all方法。下面試試

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') 
相關問題