Python + selenium + phantomjs 爬取网站信息遇到问题求助
最近公司要求爬下 http://www.kuajingjishi.com/Purchase/SearchPurchase#pageIndex=10 页面的采购信息,本以为会是比较简单的事情,结果每次爬下来都是第一页的内容
from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get(‘http://www.kuajingjishi.com/Purchase/SearchPurchase#pageIndex=2’)
result = driver.find_element_by_tag_name(‘table’)
print(result.get_attribute(‘innerHTML’))
求助求助~
Python + selenium + phantomjs 爬取网站信息遇到问题求助
python<br>import requests<br><br>data = {<br> 'X-Requested-With': 'XMLHttpRequest'<br>}<br><br>for i in range(1,10):<br> url='<a target="_blank" href="http://www.kuajingjishi.com/Purchase/SearchPurchase?pageIndex=" rel="nofollow noopener">http://www.kuajingjishi.com/Purchase/SearchPurchase?pageIndex=</a>{page}'.format(page=i)<br> r=<a target="_blank" href="http://requests.post" rel="nofollow noopener">requests.post</a>(url, data=data)<br> print(r.text)<br>
我无法理解你的问题
它是用 ajax 加载的, 浏览器里用 F12, 选 network 那个 tab, 手动点一下那几个页面, 能看到它发出去的请求, 然后自己一模一样发好了
这个站还没对请求进行验证…orz
至于为什么 selenium 弄不到…天知道:)
tips: 在请求上右键->copy->copy as cURL 然后在这个网站能直接转换为 requests 格式 https://curl.trillworks.com/
谢谢你!
这个网站好
python 爬虫只有到完全没办法,反爬实在厉害才用 selenium + phantomjs ,绝大多数情况用 requests 应付就行。


