0
私はフードネットワークからレシピタイトルをクロールしようとしていましたが、再帰的に次のページに移動したいと思います。私はそうscrapyで一部の機能が、私には利用できないのpython 3を使用したが、ここで私がこれまで持っているものだよ:Scrapy Spiderで動作しない再帰的なクロール
import scrapy
from scrapy.http import Request
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
from scrapy.selector import Selector
from scrapy.selector import HtmlXPathSelector
from testspider.items import testspiderItem
from lxml import html
class MySpider(CrawlSpider):
name = "test"
allowed_domains = ["foodnetwork.com"]
start_urls = ["http://www.foodnetwork.com/recipes/aarti-sequeira/middle-eastern-fire-roasted-eggplant-dip-babaganoush-recipe.html"]
rules = (Rule(LinkExtractor(allow=(), restrict_xpaths=('//div[@class="recipe-next"]/a/@href',)), callback="parse_page", follow= True),)
def parse(self, response):
site = html.fromstring(response.body_as_unicode())
titles = site.xpath('//h1[@itemprop="name"]/text()')
for title in titles:
item = testspiderItem()
item["title"] = title
yield item
Webページのソースからのタグは以下のとおりです。
<div class="recipe-next">
<a href="/recipes/food-network-kitchens/middle-eastern-eggplant-rounds-recipe.html">Next Recipe</a>
</div>
すべてのヘルプは次のようになりそれを感謝!
問題を解決したことはありますか? – Steve