国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python使用scrapy解析js示例

2020-02-23 05:07:16
字體:
來源:轉載
供稿:網友

代碼如下:
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", "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)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 遂宁市| 积石山| 三门峡市| 大邑县| 蕲春县| 太保市| 吕梁市| 政和县| 紫阳县| 太仆寺旗| 新泰市| 禹州市| 河池市| 绿春县| 建水县| 宁城县| 山西省| 黄平县| 舞阳县| 南川市| 盱眙县| 山阳县| 青海省| 衡水市| 榆林市| 潢川县| 疏附县| 静海县| 平泉县| 固阳县| 石渠县| 长宁县| 柳林县| 永宁县| 元谋县| 台南县| 伊春市| 连平县| 白玉县| 北流市| 连平县|