1
治療情報を返すための次の治療コードは、返された結果の最初のセットを返しますが、リンクをたどりません。コードを学習し、ここでstackoverflowで同様の結果を確認しましたが、それらを統合しても機能しませんでした。確かに、私は学んでいます。任意のポインタが評価されるだろう。治療がリンクをたどっていない
import urlparse
from scrapy.spider import BaseSpider
from scrapy.selector import Selector
from scrapy.http import Request
import w3lib.url
from yelp.items import YelpItem
class YelpSpider(BaseSpider):
name = "yelp"
download_delay = 10
concurrent_requests = 1
concurrent_requests_per_domain = 1
allowed_domains = ["yelp.com"]
start_urls = ["http://www.yelp.com/search?find_desc=cancer+treatment&find_loc=manhattan%2Cny&start=0",
"http://www.yelp.com/search?find_desc=cancer+treatment&find_loc=manhattan%2Cny&start=20",
"http://www.yelp.com/search?find_desc=cancer+treatment&find_loc=manhattan%2Cny&start=30"]
def parse(self, response):
selector = Selector(response)
for title in selector.css("span.indexed-biz-name"):
page_url = urlparse.urljoin(response.url,
title.xpath("a/@href").extract()[0])
self.log("page URL: %s" % page_url)
#continue
yield Request(page_url,
callback=self.parse_page)
for next_page in selector.css(u'ul > li > a.prev-next:contains(\u2192)'):
next_url = urlparse.urljoin(response.url,
next_page.xpath('@href').extract()[0])
self.log("next URL: %s" % next_url)
#continue
yield Request(next_url,
callback=self.parse)
def parse_page(self, response):
selector = Selector(response)
item = YelpItem()
item["name"] = selector.xpath('.//h1[@itemprop="name"]/text()').extract()[0].strip()
item["addresslocality"] = u"\n".join(
selector.xpath('.//address[@itemprop="address"]//text()').extract()).strip()
item["link"] = response.url
website = selector.css('div.biz-website a')
if website:
website_url = website.xpath('@href').extract()[0]
item["website"] = w3lib.url.url_query_parameter(website_url, "url")
return item
これは部分的に問題を解決します。 start_urlsのすべてのURLが最初に収集されていることがわかりました。その後、分析は個々のURLから開始されます。理想的には、これは最初の10個のURLを収集し、分析を行い(リンクを詳細に調べる)、リストされている次のstart_urlに進みます。 – jeffschips
@jeffschipsこれは別のフォローアップの問題だと思います。問題が発生した場合は、別のトピックを作成することを検討してください。ありがとう。 – alecxe