[問題] Scrapy 蜘蛛程式無法爬超過3個網頁
小弟是python 新手,最近想要抓一個鳥會的DataBase,但這個DataBase的頁面沒有其他
連結,於是自己以程式產出連結,並丟給爬蟲程式去爬,
程式可以正常執行,無奈程式只要爬超過三個網頁,
抓下來的資料順序就會出錯,請教各位大大,我該如何解決??
下面附上程式碼
import scrapy
import string
from scrapy.http import Request
from Birdtest.items import BirdItem
class BirdSpider(scrapy.Spider):
name = "bird"
allowed_domains = ["webdata.bird.org.tw"]
start_urls = ["http://webdata.bird.org.tw/contents.php?key=000001"]
def parse(self, response):
for sel in response.xpath('//tr/td[@colspan]'):
item = BirdItem()
item['desc'] = sel.xpath('text()').extract()
yield item
for i in xrange(2,5,1):
url="http://webdata.bird.org.tw/contents.php?key=" + str(i)
yield Request(url,self.parse)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.70.151.159
※ 文章網址: http://www.ptt.cc/bbs/Python/M.1417669492.A.269.html
推
12/05 15:42, , 1F
12/05 15:42, 1F
→
12/05 19:24, , 2F
12/05 19:24, 2F
→
12/05 19:25, , 3F
12/05 19:25, 3F
→
12/05 19:27, , 4F
12/05 19:27, 4F
→
12/05 19:28, , 5F
12/05 19:28, 5F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章