【发布时间】:2017-02-01 00:26:40
【问题描述】:
我正在尝试从 peoplefinders.com 抓取数据。但是我要检索的部分返回为空。
page = requests.get("http://www.peoplefinders.com/peoplesearch/searchresults?search=People&fn=joe&mn=&ln=jackson&city=&state=&age=&dobmm=&dobdd=&doby=1955")
tree = html.fromstring(page.content)
page.headers['Content-Type'] #'text/html; charset=utf-8'
tree.xpath('//a[@class = "reporttextblue"]') #returns []
在 html 检查中,我想要的文本部分如下:
<a class = "reporttextblue" href = "...">
text text text
<span></span>
text text text
<br/>
text text text
</a>
注意事项:
- 我在 jupyter notebook 中运行内核。
- 我在 IE 和 chrome 浏览器中都试过了,但都不起作用。
- 网站是动态的,它会变化 html 作为 ::before 和 ::after,当您最小化或最大化时。
-
运行时网站缺少文字:
tree.xpath('//text()')
我希望有人能告诉我这背后的真正原因是什么,并可能告诉我使用 Python 抓取数据的更好方法。
谢谢
【问题讨论】:
-
我在提到的页面上看不到带有
class="reporttextblue"的元素。你的意思是class="text-blue name-blue"?
标签: python xpath web-scraping jupyter