找到beautifulsoup特定文本 [英] find specific text in beautifulsoup
本文介绍了找到beautifulsoup特定文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个特定的一段文字我试图使用BeautifulSoup和Python得到的,但是我不知道如何使用sou.find()得到它。
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().
我想获得在美的#1只能从下面。
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>
")
谁能帮我?
推荐答案
您需要使用的 find_all 的汤
方法。下面尝试
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')
这篇关于找到beautifulsoup特定文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文