您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python使用scrapy解析js示例

5b51 2022/1/14 8:18:04 python 字数 3078 阅读 360 来源 www.jb51.cc/python

复制代码代码如下:fromseleniumimportselenium classMySpider(CrawlSpider):???name=\'cnbeta\'???allowed_domains=[\'cnbeta.com\']???start_urls=[\'http://www.jb5

概述

class MySpider(CrawlSpider):
    name = 'cnbeta'
    allowed_domains = ['cnbeta.com']
    start_urls = ['http://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","http://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使用scrapy解析js示例全部内容,希望文章能够帮你解决python使用scrapy解析js示例所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶