【发布时间】:2019-01-30 00:39:12
【问题描述】:
我正在抓取的 xml 提要有大约一千个项目。我想知道是否有一种方法可以拆分负载或另一种方法来显着减少运行时间。目前迭代下面链接中的所有 xml 需要两分钟。非常感谢任何建议或建议。
示例:https://www.cityblueshop.com/sitemap_products_1.xml
from scrapy.spiders import XMLFeedSpider
from learning.items import TestItem
class MySpider(XMLFeedSpider):
name = 'testing'
allowed_domains = ['www.cityblueshop.com']
start_urls = ['https://www.cityblueshop.com/sitemap_products_1.xml']
namespaces = [('n', 'http://www.sitemaps.org/schemas/sitemap/0.9')]
itertag = 'n:url'
iterator = 'xml'
def parse_node(self, response, node):
item = TestItem()
item['url'] = node.xpath('.//n:loc/text()').extract()
return item
所有项目的运行时间为两分钟。有什么方法可以让使用 Scrapy 更快?
【问题讨论】:
标签: python xml web-scraping scrapy