我正在尝试废弃一个电子商务网站,我分两步完成。在
该网站的结构如下:
现在我有两个蜘蛛:
我对Scrapy完全陌生,我遵循一些教程来实现这一点。我想知道解析函数有多复杂,规则是如何工作的。我的蜘蛛现在看起来像:
class GeneralSpider(CrawlSpider):
name = 'domain'
allowed_domains = ['domain.org']
start_urls = ['http://www.domain.org/home']
def parse(self, response):
links = LinksItem()
links['content'] = response.xpath("//div[@id='h45F23']").extract()
return links
如果分页是JQuery,这意味着URL中没有GET variable,那么可以在分页之后进行分页吗?
我可以在同一个spider中使用不同的“规则”来删除页面的不同部分吗?每只蜘蛛都有一只更专注的东西?
我也在google上搜索过任何与Scrapy有关的书,但似乎还没有完成的书,或者至少我找不到一本。在
这个2个URL适合这个例子。在Eroski Home页面中,您可以获得产品页面的URL。在
在产品页面中,您有一个分页的项目列表(Eroski items):
在Eroski Fruits页面中,项目的分页似乎是JQuery/AJAX,因为向下滚动时会显示更多的项目,有没有办法用Scrapy获取所有这些项目?在
这是非常特定于站点的,取决于分页的实现方式。在
这正是您的用例-分页是通过附加的AJAX调用进行的,您可以在Scrapy spider中模拟这些调用。在
是的,
CrawlSpider
提供的“规则”机制是一项非常强大的技术—它是高度可配置的—您可以有多个规则,其中一些规则遵循与特定条件匹配的特定链接,或者位于页面的特定部分。与拥有多个spider相比,具有多个规则的单个spider应该是首选。在关于您的具体用例,我们的想法是:
rule
来跟随主页导航菜单中的类别和子类别-这就是restrict_xpaths
会有帮助的yield
aRequest
,它将模拟浏览器在打开类别页面时发送的AJAX请求yield
另一个Request
,用于相同的类别/子类别,但增加page
GET参数(获取下一页)示例工作实现:
希望这对你来说是个好的起点。在
没什么特别的事我记得。在
虽然我听说有些出版商计划发行一本关于网络抓取的书,但我不想告诉你这些。
相关问题 更多 >
编程相关推荐