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)

相关文章

用ReactJS和Python的Flask框架编写留言板的代码示例

近期要在生产环境上使用react,所以,自己学习了一下,写了一个简单的留言板小程序。完整的代码可以到这里下载:message-board Use 前端使用React,然后还有Bootst...

Python Django模板之模板过滤器与自定义模板过滤器示例

本文实例讲述了Python Django模板之模板过滤器与自定义模板过滤器。分享给大家供大家参考,具体如下: 模板过滤器 过滤器用于对模板变量进行操作。 date:改变日期的显示格式。...

使用Django的模版来配合字符串翻译工作

Django模板使用两种模板标签,且语法格式与Python代码有些许不同。 为了使得模板访问到标签,需要将 {% load i18n %} 放在模板最前面。 这个{% trans %}模...

django 通过ajax完成邮箱用户注册、激活账号的方法

一、图片验证码 django-simple-captcha配置 1.在pycharm中,File====》Settings====》Project:项目名====》Project Int...

Python中利用xpath解析HTML的方法

在进行网页抓取的时候,分析定位html节点是获取抓取信息的关键,目前我用的是lxml模块(用来分析XML文档结构的,当然也能分析html结构), 利用其lxml.html的xpath对h...