相关疑难解决方法(0)

Scrapy按顺序抓取网址

所以,我的问题相对简单.我有一个蜘蛛爬行多个站点,我需要它按照我在代码中写入的顺序返回数据.它发布在下面.

from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from mlbodds.items import MlboddsItem

class MLBoddsSpider(BaseSpider):
   name = "sbrforum.com"
   allowed_domains = ["sbrforum.com"]
   start_urls = [
       "http://www.sbrforum.com/mlb-baseball/odds-scores/20110328/",
       "http://www.sbrforum.com/mlb-baseball/odds-scores/20110329/",
       "http://www.sbrforum.com/mlb-baseball/odds-scores/20110330/"
   ]

   def parse(self, response):
       hxs = HtmlXPathSelector(response)
       sites = hxs.select('//div[@id="col_3"]//div[@id="module3_1"]//div[@id="moduleData4952"]')
       items = []
       for site in sites:
           item = MlboddsItem()
           item['header'] = site.select('//div[@class="scoreboard-bar"]//h2//span[position()>1]//text()').extract()# | /*//table[position()<2]//tr//th[@colspan="2"]//text()').extract()
           item['game1'] = site.select('/*//table[position()=1]//tr//td[@class="tbl-odds-c2"]//text() | /*//table[position()=1]//tr//td[@class="tbl-odds-c4"]//text() | /*//table[position()=1]//tr//td[@class="tbl-odds-c6"]//text()').extract()
           items.append(item)
       return items
Run Code Online (Sandbox Code Playgroud)

结果以随机顺序返回,例如它返回第29个,然后是第28个,然后是第30个.我已经尝试将调度程序顺序从DFO更改为BFO,以防万一是问题,但这并没有改变任何东西.

python sorting asynchronous hashmap scrapy

21
推荐指数
4
解决办法
3万
查看次数

标签 统计

asynchronous ×1

hashmap ×1

python ×1

scrapy ×1

sorting ×1