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中的元组与逻辑运算符

Python元组 元组是另一个数据类型,类似于List(列表)。 元组用"()"标识。内部元素用逗号隔开。但是元素不能二次赋值,相当于只读列表。 #!/usr/bin/python...

各种Python库安装包下载地址与安装过程详细介绍(Windows版)

各种Python库安装包下载地址与安装过程详细介绍(Windows版)

在用Python开发时(Windows环境),会碰到需要安装某个版本的第三方库,为了以后查找、安装方便,总结如下: windows版的各种Python库安装包下载地址: http://w...

Python 生成 -1~1 之间的随机数矩阵方法

Python 生成 -1~1 之间的随机数矩阵方法

1. 使用函数 np.random.random 由于 np.random.random() 默认生成 0~1 之间的小数,因此需要转换一下 如生成 3*3 的 -1~1 之间的随机数...

Pyhthon中使用compileall模块编译源文件为pyc文件

有的时候我们需要把项目中.py的python所有源文件编译成.pyc文件,只保留.pyc文件然后发布给别人(虽然说可以反编译,但也算是一种保护把). 这个时候就可以使用compileal...

Python实现bilibili时间长度查询的示例代码

Python实现bilibili时间长度查询的示例代码

说明:最近在B站看一些材料力学视频时候,感觉有一些分集狂魔的分集真的很恐怖,有的甚至上百集,因此决定写个小脚本每次分析下到底这个系列视频到底有多长。 好了,下面是分析过程: 第一步当然...