2017-09-14 6 views
0

私はと思う。私がする必要があるのは非常に簡単ですが、私は単一のドメインを削るだけに集中しない良いソースを見つけるのに苦労しています。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} 
+0

allowed_domainsとstart_urlsにすべてを入れるのは簡単ですか? –

答えて

0

: -

編集は、ここで私が現在働いているクモです。

from scrapy import Spider 
from scrapy.linkextractors import LinkExtractor 

class MySpider(Spider): 
    name = 'myspider' 
    start_urls = ['http://domain1.com', 'http://domain2.com', ...] 

    def parse(self, response): 
     le = LinkExtractor() 
     for link in le.extract_links(response): 
      if link.url == 'something I want': 
       # do something 
+0

私はallowed_domainsを持っています。これには、start_urlsと同じドメインのみが含まれていますが、それでもまだソーシャルメディアサイトをクロールしています。私はresponse.urlを印刷しているので分かります。私はコードを含めるために私の質問を更新する... –

関連する問題