私はと思う。私がする必要があるのは非常に簡単ですが、私は単一のドメインを削るだけに集中しない良いソースを見つけるのに苦労しています。Scrapyでドメインのリストからすべてのリンクを取得するには?
私は約9,000のドメインのリストを持っています。それぞれについて、自分のサイトへのリンクが自分のドメインのどこにでも存在するかどうかをチェックする必要があります。基本的には、私のサイトにリンクしているリストのリストが必要です。したがって、URLの入力は9,000ですが、私のコードの結果はずっと小さくなります。
これをやり始める方法についてのヒントは非常に高く評価されます。私は複数のScrapyチュートリアルをやったことがありますが、これはまだ私が知っている情報ではありません。あなたはすべてのリンクを取得するためにLinkExtractor
を使用して、ちょうどあなたが実際に必要なものを選択することができます
# -*- coding: utf-8 -*-
import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
from urllib.parse import urlparse
class JakeSpider(CrawlSpider):
name = 'jake'
allowed_domains = ['hivedigital.com','gofishdigital.com','quizzly.co']
start_urls = ['http://hivedigital.com/', 'http://gofishdigital.com/', 'https://quizzly.co/']
rules = (
Rule(LinkExtractor(allow=()), callback='parse_item', follow=True),
)
def parse_item(self, response):
#i = {}
page = response.url
domain = urlparse(page).netloc
print("............", domain)
links = response.xpath('//a/@href').extract()
#i['name'] = response.xpath('//div[@id="name"]').extract()
#i['description'] = response.xpath('//div[@id="description"]').extract()
#return i
le = LinkExtractor()
for link in le.extract_links(response):
if link.url == 'http://twitter.com':
yield {'link':link,'domain': domain}
allowed_domainsとstart_urlsにすべてを入れるのは簡単ですか? –