【发布时间】:2019-08-17 04:47:01
【问题描述】:
我正在尝试抓取此站点上的所有产品: https://www.jny.com/collections/jackets
它将获取所有产品的链接,然后将它们一一抓取。我正在尝试通过多线程来加速这个过程。代码如下:
def yield1(self, url):
print("inside function")
yield scrapy.Request(url, callback=self.parse_product)
def parse(self, response):
print("in herre")
self.product_url = response.xpath('//div[@class = "collection-grid js-filter-grid"]//a/@href').getall()
print(self.product_url)
for pu in self.product_url:
print("inside the loop")
with ThreadPoolExecutor(max_workers=10) as executor:
print("inside thread")
executor.map(self.yield1, response.urljoin(pu))
它应该创建一个包含 10 个线程的池,每个线程将在 URL 列表上执行 yield1()。问题是没有调用 yield1() 方法。
【问题讨论】:
-
你使用的是 asyncio 还是 concurrent.futures?
-
concurrent.futures
-
您不应该捕获期货并在完成后对其进行迭代吗? docs.python.org/3/library/…
-
给出这个错误:Request 类型的对象没有 len
标签: python multithreading scrapy python-multithreading