【发布时间】:2017-01-17 14:33:05
【问题描述】:
你好,这是我第一次发帖,
所以我正在尝试制作一个网络蜘蛛,它将跟随 invia.cz 中的链接并复制酒店的所有标题。
import scrapy
y=0
class invia(scrapy.Spider):
name = 'Kreta'
start_urls = ['https://dovolena.invia.cz/?d_start_from=13.01.2017&sort=nl_sell&page=1']
def parse(self, response):
for x in range (1, 9):
yield {
'titles':response.css("#main > div > div > div > div.col.col-content > div.product-list > div > ul > li:nth-child(%d)>div.head>h2>a>span.name::text"%(x)).extract() ,
}
if (response.css('#main > div > div > div > div.col.col-content >
div.product-list > div > p >
a.next').extract_first()):
y=y+1
go = ["https://dovolena.invia.cz/d_start_from=13.01.2017&sort=nl_sell&page=%d" % y]
print go
yield scrapy.Request(
response.urljoin(go),
callback=self.parse
)
在这个网站中,页面加载了 AJAX,所以我手动更改了 URL 的值,只有当页面中出现下一个按钮时才会增加 1。
在scrapy shell中,当我测试按钮是否出现并且条件一切正常时,但是当我启动蜘蛛时它只抓取第一页。
这是我的第一个蜘蛛,提前感谢。
还有错误日志Error Log1Error Log
【问题讨论】:
-
请分享日志,你得到了什么错误?
-
@eLRuLL 如果你想检查它们,我发布了错误日志
-
@Granitosaurus 你检查了代码吗?
标签: ajax web-scraping scrapy