我尝试使用scrapy填写POST表格,试图预订火车票。
我认为FormRequest类可以做到这一点,但我不能处理javascript表单。 Scrapy爬虫没有返回任何东西。
我使用的文件足以发送表格。
import scrapy
from scrapy.item import Item, Field
from scrapy.http import FormRequest
from scrapy.spider import BaseSpider
class SncfItem(Item):
title = Field()
link = Field()
desc = Field()
class SncfSpider(scrapy.Spider):
name = "sncf"
allowed_domains = ["voyages-sncf.com"]
start_urls = (
'http://www.voyages-sncf.com/billet-train',
)
def parse(self, response):
yield FormRequest.from_response(response,
formname='saisie',
formdata={'ORIGIN_CITY': 'Gare de Lyon (Paris)',
'DESTINATION_CITY': 'Lyon Part-Dieu',
'OUTWARD_DATE': '03.06.2015'},
callback=self.parse1)
def parse1(self, response):
print response.status
如果我在使用mySpider时错过了一步,有人能告诉我吗?
非常感谢任何帮助 感谢' S
scrapy crawl sncf -o items.xml -t xml
2015-06-01 23:13:54+0200 [sncf] INFO: Spider opened
2015-06-01 23:13:54+0200 [sncf] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2015-06-01 23:13:54+0200 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6024
2015-06-01 23:13:54+0200 [scrapy] DEBUG: Web service listening on 127.0.0.1:6081
2015-06-01 23:13:55+0200 [sncf] DEBUG: Crawled (200) <GET http://www.voyages-sncf.com/billet-train> (referer: None)
2015-06-01 23:13:56+0200 [sncf] DEBUG: Redirecting (302) to <GET http://www.voyages-sncf.com/billet-train> from <POST http://www.voyages- sncf.com/vsc/train-ticket/>
2015-06-01 23:13:56+0200 [sncf] DEBUG: Crawled (200) <GET http://www.voyages-sncf.com/billet-train> (referer: http://www.voyages- sncf.com/billet-train)
200
2015-06-01 23:13:56+0200 [sncf] INFO: Closing spider (finished)
答案 0 :(得分:2)
您正在获取重定向,因为日期格式无效。
我在Scrapy shell中重播了该请求,执行以下操作:
ce::string process_name;
查看结果,我看到了日期的验证错误消息,说:“Le format de la date d'aller que vous avez saisi est wrong。Nous vousinvitonsàutiliserle calendrier。”