【问题标题】:Access and webscrape dynamic pages using python使用 python 访问和抓取动态页面
【发布时间】:2016-11-27 05:41:48
【问题描述】:
我正在尝试使用它的表单参数访问网页。
我在 chrome 的开发人员选项卡中使用网络标题找到了表单参数。
但它不起作用,只是在使用这些参数之前打开页面(即www.irishancestors.ie/search/townlands/ded_index.php)
import webbrowser
webbrowser.open('http://www.irishancestors.ie/search/townlands/ded_index.php?action=listp&parish=Aghagallon')
我的目的是检索所有县的每个区选举司的所有表格。
【问题讨论】:
标签:
python
dynamic
web-scraping
web-crawler
http-post
【解决方案1】:
webbrowser 并没有按照你的想法去做。
如果你想获取/发布数据到网页,你应该使用requests
>>> import requests
>>> r = requests.get('https://api.github.com/events')
>>> r = requests.post('http://httpbin.org/post', data = {'key':'value'})
webbrowser 用于启动您的网络浏览器。
请注意,如果使用大量 javascript,这将不会很好地工作(嗯,它可能会,但它需要您做更多的工作)。如果你有很多Javascript,使用selenium可能会更容易