python使用scrapy解析js示例

yipeiwu_com6年前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中,可以使用标准库inspect的一些方法或类,来操作或创建函数签名。 获取函数签名及参数 使用标准库的sig...

Python Requests 基础入门

首先,Python 标准库中的 urllib2 模块提供了你所需要的大多数 HTTP 功能,但是它的 API 不友好。它是为另一个时代、另一个互联网所创建的。它需要巨量的工作,甚至包括各...

python编程培训 python培训靠谱吗

python编程培训 python培训靠谱吗

我们在论坛和贴吧上看到无论是老的程序员和新手都想更快的入门和精通python编程,但是市面上众多的书籍让大家无从下手,很多书籍和视频都声称能够快速学习,时间有限,大家哪有精力一个个尝试呢...

计算机二级python学习教程(3) python语言基本数据类型

计算机二级python学习教程(3) python语言基本数据类型

本文继续计算机二级python教程的学习,之前已经学习过了计算机二级python学习教程(1) 、计算机二级python学习教程(2) 3.1 数字类型 数字类型:整数类型、浮点数类型、...

Python设计模式之观察者模式原理与用法详解

Python设计模式之观察者模式原理与用法详解

本文实例讲述了Python设计模式之观察者模式原理与用法。分享给大家供大家参考,具体如下: 观察者模式(发布-订阅模式 Publish Subscribe Pattern):定义了一种一...