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语言中提供了类似于C++的运算符重在功能: 一下为Python运算符重在调用的方法如下: Met...

Python多进程同步Lock、Semaphore、Event实例

同步的方法基本与多线程相同。 1) Lock 当多个进程需要访问共享资源的时候,Lock可以用来避免访问的冲突。 复制代码 代码如下: import multiprocessing im...

Python使用cx_Oracle调用Oracle存储过程的方法示例

本文实例讲述了Python使用cx_Oracle调用Oracle存储过程的方法。分享给大家供大家参考,具体如下: 这里主要测试在Python中通过cx_Oracle调用PL/SQL。 首...

python3.x上post发送json数据

python3.x上post发送json数据

一.摘要 做接口自动化测试时,常常需要使用python发送一些json内容的接口报文,如果使用urlencode对内容进行编码解析并发送请求,会发现服务器返回了200,OK的状态,但响应...

python虚拟环境迁移方法

python虚拟环境迁移方法

python虚拟环境迁移: 注意事项:直接将虚拟环境复制到另一台机器,直接执行是会有问题的。 那么可以采用以下办法: 思路:将机器1虚拟环境下的包信息打包,之后到机器2上进行安装; (有...