作者allen511081 (蓝)
看板Python
标题[问题] Scrapy 蜘蛛程式无法爬超过3个网页
时间Thu Dec 4 13:04:49 2014
小弟是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://webptt.com/cn.aspx?n=bbs/Python/M.1417669492.A.269.html
1F:推 goldflower: 顺序出错的具体状况是@@? 12/05 15:42
2F:→ allen511081: 例如:第一页有25笔资料,第二页有30笔资料,第三页 12/05 19:24
3F:→ allen511081: 有35笔资料,第4页有40笔资料,程式会先抓page1的10 12/05 19:25
4F:→ allen511081: 笔资料後,继续去page2抓几笔资料,依此类推,但是 12/05 19:27
5F:→ allen511081: 最後检查资料,资料却是一笔都不少的抓下来 12/05 19:28