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)

相关文章

在PyCharm下打包*.py程序成.exe的方法

如下所示: 1. 在PyCharm下安装pyinstaller 2. 在Terminal下输入:“pyinstaller -F -w *.py” 就可以制作出exe。生成的文件放在同目录...

Python 专题五 列表基础知识(二维list排序、获取下标和处理txt文本实例)

Python 专题五 列表基础知识(二维list排序、获取下标和处理txt文本实例)

通常测试人员或公司实习人员需要处理一些txt文本内容,而此时使用Python是比较方便的语言。它不光在爬取网上资料上方便,还在NLP自然语言处理方面拥有独到的优势。这篇文章主要简单的介绍...

python双向链表原理与实现方法详解

本文实例讲述了python双向链表原理与实现方法。分享给大家供大家参考,具体如下: 双向链表 一种更复杂的链表是“双向链表”或“双面链表”。每个节点有两个链接:一个指向前一个节点,当此节...

CentOS 6.X系统下升级Python2.6到Python2.7 的方法

第一步:升级python CentOs 6.x的系统默认安装的Python版本是2.6.x,想升级到Python2.7.x,从官方下载源文件,然后解压、编译 wget http:...

python机器学习理论与实战(二)决策树

python机器学习理论与实战(二)决策树

        决策树也是有监督机器学习方法。 电影《无耻混蛋》里有一幕游戏,在德军小酒馆里有几个人在玩20问题游戏...