-1
我想創建一個能夠在每個網站上的url爬行器之間跳轉的bot。 使用scrapy跳到爬網url
如果在網站上有兩個網址,我想開始2個新的實例抓取那裏的網站。
可能同時限制實例的個數。
我的代碼實際上只適用於1個網站,它無法跳轉到獲取網址。
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import HtmlXPathSelector
from scrapy.item import Item
from scrapy.spider import BaseSpider
from scrapy import log
class ExampleSpider(CrawlSpider):
name = "crawler"
allowed_domains = ["*"]
start_urls = ["http://domainA.com"]
rules = [Rule(SgmlLinkExtractor(), callback='parse_item', follow=True)]
def parse_item(self,response):
self.log('A response from %s just arrived!' % response.url)
你能提供一個真實的世界reproduceable例子關注的是你的期望的輸出是什麼?謝謝。 – alecxe
您可以使用工作池(在這種情況下,您可以使用隊列)。因此,您有一個負責創建作業(要爬網的URL)並將其插入隊列的進程。然後,您可以使用多個線程從池中獲取工作,因爲隊列在它們之間共享。 –
@alecxe放入數據庫過期的域名。 – Pixel