Python 在多页上递归使用scrapy get链接
我正在使用我在网上找到的以下代码递归地刮取多页上的链接。它应该递归地返回我在所有页面上需要的所有链接。但最终我最多只能得到100个链接。任何建议都会有帮助Python 在多页上递归使用scrapy get链接,python,web-scraping,scrapy,scrapy-spider,Python,Web Scraping,Scrapy,Scrapy Spider,我正在使用我在网上找到的以下代码递归地刮取多页上的链接。它应该递归地返回我在所有页面上需要的所有链接。但最终我最多只能得到100个链接。任何建议都会有帮助 class MySpider(CrawlSpider): name = "craigs" allowed_domains = ["craigslist.org"] start_urls = ["http://seattle.craigslist.org/search/jjj?is_parttime=1"]
class MySpider(CrawlSpider):
name = "craigs"
allowed_domains = ["craigslist.org"]
start_urls = ["http://seattle.craigslist.org/search/jjj?is_parttime=1"]
rules = (Rule (SgmlLinkExtractor(allow=("index\d00\.html", ),restrict_xpaths=('//a[@class="button next"]',))
, callback="parse_items", follow= True),
)
def parse_items(self, response):
hxs = HtmlXPathSelector(response)
titles = hxs.select('//span[@class="pl"]')
items = []
for titles in titles:
item = CraigslistSampleItem()
item ["title"] = titles.select("a/text()").extract()
item ["link"] = titles.select("a/@href").extract()
items.append(item)
return(items)
只需删除
allow=(“index\d00\.html)”
即可让它解析下一个链接:
rules = (Rule(SgmlLinkExtractor(restrict_xpaths=('//a[@class="button next"]',)),
callback="parse_items", follow= True),)