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解析nginx日志文件

项目的一个需求是解析nginx的日志文件。 简单的整理如下: 日志规则描述 首先要明确自己的Nginx的日志格式,这里采用默认Nginx日志格式: log_format main...

python缩进区别分析

仔细观察下面两个python程序,代码一模一样,但是运行的结果却不同,就是因为最后一行return缩进的不同复制代码 代码如下:def powersum(power, *args): '...

python异步任务队列示例

很多场景为了不阻塞,都需要异步回调机制。这是一个简单的例子,大家参考使用吧复制代码 代码如下:#!/usr/bin/env python# -*- coding: UTF-8 -*-im...

python 函数的缺省参数使用注意事项分析

本文实例讲述了python 函数的缺省参数使用注意事项。分享给大家供大家参考,具体如下: python的函数支持4种形式的参数:分别是必选参数、 缺省参数、 可变长参数、关键字参数;而且...

答题辅助python代码实现

本文实例为大家分享了答题辅助python具体代码,供大家参考,具体内容如下 from screenshot import pull_screenshot import time, u...