【发布时间】:2015-10-16 17:30:15
【问题描述】:
我将分析许多具有不同 html 的网站,并尝试使用 BeautifulSoup 查找包含特定文本(在 html 内)的所有行。
r = requests.get(url)
soup = BeautifulSoup(r.content, "lxml")
for text in soup.find_all():
if "price" in text:
print text
这种方法不起作用(即使“价格”在 html 中被提及超过 40 倍)。也许有更好的方法来做到这一点?
【问题讨论】:
-
您是否有理由要使用
BeautifulSoup?似乎如果您只想要包含价格的行,那么直接查看响应数据可能会更容易。最终目标是什么?
标签: python html parsing beautifulsoup