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自动保存百度盘资源到百度盘中的实例代码

本实例的实现逻辑是,应用selenium UI自动化登录百度盘,读取存储百度分享地址和提取码的txt文档,打开百度盘分享地址,填入提取码,然后保存到指定的目录中 全部代码如下: #...

python3对接mysql数据库实例详解

python3对接mysql数据库实例详解

Python3 MySQL数据库连接,假设MySQL数据库已经安装好了,并创建好了数据库(后面抽点时间将数据库的安装总结下)。  PyMySQL是Python3中用于连接MyS...

python实现的登录和操作开心网脚本分享

SNS什么的我是一直无爱的,这次蛋疼写了个登录开心网(kaixin001)并向所有好友发送站内消息的脚本。 开心网在登录的时候做了一些处理,并不传原始密码,从js分析到的结果是:登录时会...

python微信跳一跳系列之自动计算跳一跳距离

python微信跳一跳系列之自动计算跳一跳距离

到现在为止,我们通过前面几篇博文的描述和分析,已经可以自动实现棋子、棋盘位置的准确判断,计算一下两个中心点之间的距离,并绘制在图形上,效果如下。 效果 图中的棋子定位采用HSV颜色识别...

Python做简单的字符串匹配详解

Python做简单的字符串匹配详解  由于需要在半结构化的文本数据中提取一些特定格式的字段、数据辅助挖掘分析工作,以往都是使用Matlab工具进行结构化数据处理的建模,matl...