2017-12-17 28 views
1

プログラミング初回治療、ページをクロールできません: "TCP接続がタイムアウトしました:110:接続がタイムアウトしました。"

同じウェブサイトに属する一部のドメインのコンテンツをスクラップできません。

たとえば、私はit.example.com、es.example.com、pt.example.comを削ることができますが、私がfr.example.comやus.example.comで同じことをしようとすると、 :

    2017-12-17 14:20:27 [scrapy.extensions.telnet] DEBUG: Telnet console 
    listening on 127.0.0.1:6025 
    2017-12-17 14:21:27 [scrapy.extensions.logstats] INFO: Crawled 0 pages 
    (at 
    0 pages/min), scraped 0 items (at 0 items/min) 
    2017-12-17 14:22:27 [scrapy.extensions.logstats] INFO: Crawled 0 pages 
    (at 
    0 pages/min), scraped 0 items (at 0 items/min) 
    2017-12-17 14:22:38 [scrapy.downloadermiddlewares.retry] DEBUG: 
    Retrying 
    <GET https://fr.example.com/robots.txt> (failed 1 times): TCP 
    connection 
    timed out: 110: Connection timed out. 
    

    は、ここで私が試してみました何スパイダーsome.py

    import scrapy 
    import itertools 
    
    class SomeSpider(scrapy.Spider): 
        name = 'some' 
        allowed_domains = ['https://fr.example.com'] 
        def start_requests(self): 
        categories = [ 'thing1', 'thing2', 'thing3',] 
          base = "https://fr.example.com/things?t={category}&p={index}" 
    
        for category, index in itertools.product(categories, range(1, 11)): 
         yield scrapy.Request(base.format(category=category, index=index)) 
    
    def parse(self, response): 
        response.selector.remove_namespaces() 
        info1 = response.css("span.info1").extract() 
        info2 = response.css("span.info2").extract() 
    
        for item in zip(info1, info2): 
         scraped_info = { 
          'info1': item[0], 
          'info2': item[1] 
          } 
    
         yield scraped_info 
    

    にです

  1. ランは、異なるIP(同じドメインと同じ問題)

  2. からクモはStackOverflowの上のどこかに見つけ

  3. (動作しませんでした)IPアドレスのプールを追加します。setting.py、セットで

    USER_AGENT = 'Mozilla/5.0(Macintosh;ヤモリのようなインテルのMac OS X 10_10_5) のAppleWebKit/537.36(KHTML、)クローム/ 55.0.2883.95 サファリ/ 537.36'

  4. ROBOTSTXT_OBEY = Falseの

はすべてのアイデアは大歓迎です!

+0

今日はブラウザでこのURLを確認しましたか?多分サーバーに問題があり、うまくいかないかもしれません。 – furas

+0

最初にブラウザをチェックしてから、scrapyを参照してください。一部のサイトには特定の国のIPが必要です –

+0

サイトはオンラインで、問題なく現在の場所からアクセスできます – Rawhide

答えて

0

scrapyの代わりにrequestsパッケージのページにアクセスして、それが機能するかどうかを確認してください。

import requests 

url = 'fr.example.com' 

response = requests.get(url) 
print(response.text) 
+0

それは魅力のように働いた。私が必要とする情報を掻き集めるためにスクリプトで何を変更しなければならないのですか? – Rawhide

+0

EDIT:何らかの理由で、他のドメインで機能していたのと同じ_base = "https://fr.example.com/things?t={category}&p={index}"_、FRと米国では使用できませんでした。私はただwwwを追加しました。 fr.example.comに送信して機能しました。 _base = "https://www.fr.example.com/things?t={category}&p={index}"_が働いています。理由は分かりません。 – Rawhide

+0

@Rawhideうれしい私の答えはまだ有用だった。 – laguittemh

関連する問題