【发布时间】:2016-07-10 08:55:30
【问题描述】:
我正在尝试使用 Scrapy 蜘蛛来抓取网站,使用 FormRequest 将关键字发送到特定城市页面上的搜索查询。我读到的内容似乎很简单,但我遇到了麻烦。对 Python 来说相当新,如果有明显的我忽略了,很抱歉。
以下是我试图用来帮助我的主要 3 个网站: 鼠标与 Python [1]; Stack Overflow; Scrapy.org [3]
来自我正在爬取的具体url的源码:www.lkqpickyourpart.com\locations/LKQ_Self_Service_-_Gainesville-224/recents
从我找到的特定页面的来源:
<input name="dnn$ctl01$txtSearch" type="text" maxlength="255" size="20" id="dnn_ctl01_txtSearch" class="NormalTextBox" autocomplete="off" placeholder="Search..." />
我认为搜索的名称是“dnn_ct101_txtSearch”,我将在我发现引用为2 的示例中使用它,并且我想在车辆搜索中输入“toyota”作为我的关键字。
这是我现在的蜘蛛代码,我知道我在开始时导入了过多的东西:
import scrapy
from scrapy.http import FormRequest
from scrapy.item import Item, Field
from scrapy.http import FormRequest
from scrapy.spider import BaseSpider
class LkqSpider(scrapy.Spider):
name = "lkq"
allowed_domains = ["lkqpickyourpart.com\locations/LKQ_Self_Service_-_Gainesville-224/recents"]
start_urls = ['http://www.lkqpickyourpart.com\locations/LKQ_Self_Service_-_Gainesville-224/recents/']
def start_requests(self):
return [ FormRequest("www.lkqpickyourpart.com\locations/LKQ_Self_Service_-_Gainesville-224/recents",
formdata={'dnn$ctl01$txtSearch':'toyota'},
callback=self.parse) ]
def parsel(self):
print self.status
为什么它不搜索或打印任何类型的结果,我复制的示例是否仅用于登录不进入搜索栏的网站?
谢谢, Dan 新手 Python 作家
【问题讨论】:
标签: python scrapy web-crawler scrapy-spider