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函数中return后的语句一定不会执行吗?

前言 return语句用于退出函数,向调用方返回一个表达式。return在不带参数的情况下(或者没有写return语句),默认返回None。None是一个特殊的值,它的数据类型是None...

python optparse模块使用实例

使用命令行时,如果要添加选项的话,python 2.3里新增加了一个模块叫optparse,也是专门来处理命令行选项的。 复制代码 代码如下: from optparse import...

python实现socket端口重定向示例

python实现socket端口重定向示例

可以很轻松的在端口12345开启共享,效果如下: 要实现我想要的功能,只需要将端口重定向就行了,代码如下: 复制代码 代码如下:#! /usr/bin/python''' &n...

python版百度语音识别功能

python版百度语音识别功能

本文实例为大家分享了python版百度语音识别功能的具体代码,供大家参考,具体内容如下 环境:使用的IDE是Pycharm 1.新建工程 2.配置百度语音识别环境 “File”——“Se...

手写一个python迭代器过程详解

分析 我们都知道一个可迭代对象可以通过iter()可以返回一个迭代器。 如果想要一个对象称为可迭代对象,即可以使用for,那么必须实现__iter __()方法。 在一个类...