作者:
ug945 (ug945)
2014-12-13 02:50:53※ 引述《allen511081 (藍)》之銘言:
: 小弟是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)
1.在start_request()中產生連結或是直接寫死在start_urls中
2.xpath要限定範圍或數量