我试图递归地从https://iowacity.craigslist.org/search/jjj中删除作业的标题。也就是说,我希望蜘蛛能够抓住第1页的所有职位,然后按照底部的“下一步>”链接去抓下一页,等等。我模仿迈克尔赫尔曼的教程写我的蜘蛛。 http://mherman.org/blog/2012/11/08/recursively-scraping-web-pages-with-scrapy/#.ViJ6rPmrTIU。递归挖掘后没有数据抓取
这里是我的代码:
import scrapy
from craig_rec.items import CraigRecItem
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
class CraigslistSpider(CrawlSpider):
name = "craig_rec"
allowed_domains = ["https://craigslist.org"]
start_urls = ["https://iowacity.craigslist.org/search/jjj"]
rules = (
Rule(SgmlLinkExtractor(allow=(), restrict_xpaths=('//a[@class="button next"]',)), callback="parse_items", follow= True),
)
def parse_items(self, response):
items = []
for sel in response.xpath("//span[@class = 'pl']"):
item = CraigRecItem()
item['title'] = sel.xpath("a/text()").extract()
items.append(item)
return items
我发布的蜘蛛,但没有数据被刮掉。任何帮助?谢谢!
为什么你需要两次提出同样的问题,如果解决方案对于你的两只蜘蛛都是一样的? – GHajba