python使用scrapy解析js示例

yipeiwu_com5年前Python基础

复制代码 代码如下:

from selenium import selenium

class MySpider(CrawlSpider):
    name = 'cnbeta'
    allowed_domains = ['cnbeta.com']
    start_urls = ['//www.jb51.net']

    rules = (
        # Extract links matching 'category.php' (but not matching 'subsection.php')
        # and follow links from them (since no callback means follow=True by default).
        Rule(SgmlLinkExtractor(allow=('/articles/.*\.htm', )),
             callback='parse_page', follow=True),

        # Extract links matching 'item.php' and parse them with the spider's method parse_item
    )

    def __init__(self):
        CrawlSpider.__init__(self)
        self.verificationErrors = []
        self.selenium = selenium("localhost", 4444, "*firefox", "//www.jb51.net")
        self.selenium.start()

    def __del__(self):
        self.selenium.stop()
        print self.verificationErrors
        CrawlSpider.__del__(self)


    def parse_page(self, response):
        self.log('Hi, this is an item page! %s' % response.url)
        sel = Selector(response)
        from webproxy.items import WebproxyItem

        sel = self.selenium
        sel.open(response.url)
        sel.wait_for_page_to_load("30000")
        import time

        time.sleep(2.5)

相关文章

Python多项式回归的实现方法

Python多项式回归的实现方法

多项式回归是一种线性回归形式,其中自变量x和因变量y之间的关系被建模为n次多项式。多项式回归拟合x的值与y的相应条件均值之间的非线性关系,表示为E(y | x) 为什么多项式回归:...

python进阶之自定义可迭代的类

自定义可迭代的类 列表可以获取列表的长度,然后使用变量i对列表索引进行循环,也可以获取集合的所有元素,且容易理解。没错,使用列表的代码是容易理解,也很好操作,但这是要付出代价的。列表之所...

Python快速从注释生成文档的方法

Python快速从注释生成文档的方法

作为一个标准的程序猿,为程序编写说明文档是一步必不可少的工作,如何才能写的又好又快呢,下面我们就来详细探讨下吧。 今天将告诉大家一个简单平时只要注意的小细节,就可以轻松生成注释文档,也可...

python九九乘法表的实例

python九九乘法表的实例

python2.7 for i in range(1,10): for j in range(1,i+1): print j,'x',i,'=',j*i,'\t', prin...

一键搞定python连接mysql驱动有关问题(windows版本)

对于mysql驱动问题折腾了一下午,现共享出解决方案 1:手动安装驱动 完全是场噩梦,推荐大家采用自动安装 2:自动安装 下载自动安装包,下载地址:https://www.jb51.ne...