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 pip安装包出现:Failed building wheel for xxx错误的解决

出现原因:缺失相应的whl文件。 解决办法:下载并安装对应的whl文件。 提供一个whl文件的下载网址:http://www.lfd.uci.edu/~gohlke/pythonlibs...

PyQt5每天必学之滑块控件QSlider

PyQt5每天必学之滑块控件QSlider

QSlider 是一个具有可来回拉动手柄的控件。有时使用滑块比输入数字或使用旋转框更方便。 在我们的例子中,我们将创建一个滑块和一个标签。标签显示图像。滑块将控制标签显示的图像。 #...

python实现本地图片转存并重命名的示例代码

//有1-22个文件夹,各文件夹下有Detect_0文件夹,此文件夹下有source与mask文件夹,目的是将需要获取图片的 文件夹下的图片复制到新的文件夹下并按顺序重命名 impo...

Python API自动化框架总结

Python API自动化框架总结

学完了Python脚本接口自动化之后,一直没有对该框架做总结,今天终于试着来做一份总结了。 框架结构如下图: 来说一下每个目录的作用: Configs:该目录下存放的是.conf,.i...

Python中map和列表推导效率比较实例分析

本文实例讲述了Python中map和列表推导效率比较。分享给大家供大家参考。具体分析如下: 直接来测试代码吧: #!/usr/bin/env python # -*- coding...