|
查找出陷阱url和不可见的value代码 from selenium import webdriver#from selenium.webdriver.remote.webelement import WebElementurl = 'http://pythonscraping.com/pages/itsatrap.html'driver = webdriver.PhantomJS(executable_path="phantomjs.exe")
driver.get(url)
links = driver.find_elements_by_tag_name("a")for link in links:if not link.is_displayed():print "the link "+link.get_attribute("href")+"is a trap"fields = driver.find_elements_by_tag_name("input")for field in fields:if not field.is_displayed():print "do not change value of "+field.get_attribute("name")
结果就是 the link http://pythonscraping.com/dontgohereis a trapdo not change value of phonedo not change value of email 方法5:采用分布式爬取基于Python,scrapy,redis的分布式爬虫实现框架 分布式爬取,针对比较大型爬虫系统,实现步骤如下所示1.基本的http抓取工具,如scrapy2.避免重复抓取网页,如Bloom Filter3.维护一个所有集群机器能够有效分享的分布式队列4.将分布式队列和Scrapy结合5.后续处理,网页析取(python-goose),存储(Mongodb)(知乎上看到的补充一下)
采用Scrapy的例子,请参考这里基于Scrapy对Dmoz进行抓取 方法6:进行模拟登陆这个就太多了,一般用Selenium,可以结合Firefox或者是无头浏览器PhantomJS,这个做的东西比较多了,如果感兴趣,可以点击这些,进行查看,方法,代码,解析,一应俱全 Pay Attention1.上述实验的代理ip只对当前数据有效,如果你自己想实验,请自己选择比较新的代理ip,我这个ip可能过一段时间就废了 2.目前我主要采用的方法就是采用加请求头挂上代理ip的方法,对用JS写的网站,requests抓不全数据,所以采用Selenium+PhantomJS/Firefox的方法 3.暂且学到这么多,自己总结了下,以后再补充。
注:相关网站建设技巧阅读请移步到建站教程频道。 (编辑:温州站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|