こんにちは私はウェブサイトのニュースをクロールするためのスクラップを使用していますが、このプロセスを行うとエラーが発生します。ウェブサイトには多くのニュースページがあり、ニュースのURLはwww.example.com/34223ですこの問題を修正するための方法を見つけようと、彼女はscrapyのバージョンは1.4.0である私のコードであり、私はそれが今の仕事だMACOS詐欺師のウェブサイト
import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
class Example(scrapy.Spider):
name = "example"
allowed_domains = ["http://www.example.com"]
start_urls = ["http://www.example.com"]
rules = (
#self.log('testing rules' + response.url)
# Extract links matching 'category.php' (but not matching 'subsection.php')
# and follow links from them (since no callback means follow=True by default).
Rule(LinkExtractor(allow=('/*',), deny=(' ',))),
# Extract links matching 'item.php' and parse them with the spider's method parse_item
Rule(LinkExtractor(allow=('item\.php',)), callback='parse_item'),
)
def parse_item(self, response):
self.logger.info('Hi, this is an item page! %s', response.url)
item = scrapy.Item()
item['title'] = response.xpath('/html/body/div[3]/div/div/div[1]/div[1]/div/div[2]/text()').extract()
item['img_url'] = response.xpath('/html/body/div[3]/div/div/div[1]/div[1]/div/div[3]/img').extract()
item['description'] = response.xpath('/html/body/div[3]/div/div/div[1]/div[1]/div/div[5]/text()').extract()
return item
このエラーが発生すると、エラーが発生します。スパイダーエラー処理(リファラー:なし) – Raed
'allowed_domains = [" http://www.example.com "]'を 'allowed_domains = [" www .example.com "]'、それが動作するかどうかを確認してください –