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)

相关文章

Django中的Signal代码详解

Django中的Signal代码详解

本文研究的主要是Django开发中的signal 的相关内容,具体如下。 前言 在web开发中, 你可能会遇到下面这种场景: 在用户完成某个操作后, 自动去执行一些后续的操作. 譬如用...

python socket 超时设置 errno 10054

python socket.error: [Errno 10054] 远程主机强迫关闭了一个现有的连接。问题解决方案: 前几天使用python读取网页。因为对一个网站大量的使用urlop...

详解Python的单元测试

如果你听说过“测试驱动开发”(TDD:Test-Driven Development),单元测试就不陌生。 单元测试是用来对一个模块、一个函数或者一个类来进行正确性检验的测试工作。 比如...

matlab中实现矩阵删除一行或一列的方法

实例如下所示: >> A=[1,2,3;4,5,6;7,8,9] A = 1 2 3 4 5 6 7 8 9 删除行: >> A...

windows上安装python3教程以及环境变量配置详解

windows上安装python3教程以及环境变量配置详解

1.在浏览器搜索python.org,如下图选择第一个 2.进入python官网,选择dowload然后选择windows如下图: 3.选择python3.6并下载 4.下载...