【发布时间】:2016-06-01 22:27:04
【问题描述】:
如果我使用:
import requests
from lxml import html
response = request.get(url='someurl')
tree = html.document_fromstring(response.text)
all_text = tree.xpath('//text()') # which give all text from page
在这个 all_text 列表中,我们拥有页面中的所有文本。现在我想知道:
text_searched = all_text[all_text.index('any string which is in all_text list')]
是否可以到达被搜索文本的网页元素?
【问题讨论】:
-
我认为 BeatuifulSoup 对你来说是一个更好的选择。
标签: python parsing web-scraping python-requests lxml