selenium与scrapy的动态页面

selenium与scrapy的动态页面,第1张

selenium与scrapy的动态页面

这实际上取决于你需要如何刮取网站以及你希望如何以及要获取什么数据。

这是一个示例,你可以使用

Scrapy
+ 跟踪eBay上的分页
Selenium

import scrapyfrom selenium import webdriverclass ProductSpider(scrapy.Spider):    name = "product_spider"    allowed_domains = ['ebay.com']    start_urls = ['http://www.ebay.com/sch/i.html?_odkw=books&_osacat=0&_trksid=p2045573.m570.l1313.TR0.TRC0.Xpython&_nkw=python&_sacat=0&_from=R40']    def __init__(self):        self.driver = webdriver.Firefox()    def parse(self, response):        self.driver.get(response.url)        while True: next = self.driver.find_element_by_xpath('//td[@]/a') try:     next.click()     # get the data and write it to scrapy items except:     break        self.driver.close()

除了必须与结合使用之外

Selenium
,还有另一种选择
Scrapy



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/4903308.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存