2

全て、

スクレイピングを完全に自動化しようとしていますが、これは 3 つのステップで構成されています。

1- 広告のインデックス ページのリストを取得する (さまざまな理由から非スクレイピー作業) 2- ステップ 1 で取得したインデックス ページから広告 URL のリストを取得する (スクレイピー作業)

私のスクレイピープロジェクトは通常のディレクトリにあります:

C:\Python27\Scripts\GetAdUrlsFromIndex_project\GetAdUrlsFromIndex\spiders\GetAdUrls_spider.py (「GetAdUrls_spider」ファイル内のスパイダーの名前は (name = 「getadurls」))

ステップ 1 と 2 を自動化するスクリプトは、次のディレクトリにあります。

C:\Website_DATA\SCRIPTS\StepByStepLauncher.py

Scrapy のドキュメントを使用してクローラーをインポートし、次のコードを使用してスクリプト内から実行しようとしました。

from twisted.internet import reactor
from scrapy.crawler import Crawler
from scrapy.settings import Settings
from scrapy import log
from GetAdUrlsFromIndex.spiders.GetAdUrls_spider import getadurls

spider = getadurls(domain='website.com')
crawler = Crawler(Settings())
crawler.configure()
crawler.crawl(spider)
crawler.start()
log.start()
reactor.run() # the script will block here

残念ながら、このスクリプトを実行しようとすると、「GetAdUrlsFromIndex.spiders.GetAdUrls_spider という名前のモジュールがありません」というエラーが表示され続けます.作業ディレクトリをいくつかの異なる場所に変更しようとしましたが、名前をいじってみましたが、何も機能していないようでした..

助けていただければ幸いです..ありがとう!

4

1 に答える 1

-1

持っている場合は、この方法でスクリプトを変更してみ__init__.pyC:\Python27\Scripts\GetAdUrlsFromIndex_project\GetAdUrlsFromIndexくださいC:\Python27\Scripts\GetAdUrlsFromIndex_project\GetAdUrlsFromIndex\spiders

import sys
from twisted.internet import reactor
from scrapy.crawler import Crawler
from scrapy.settings import Settings
from scrapy import log

sys.path.append('C:/Python27/Scripts/GetAdUrlsFromIndex_project')
from GetAdUrlsFromIndex.spiders.GetAdUrls_spider import getadurls

spider = getadurls(domain='website.com')
crawler = Crawler(Settings())
crawler.configure()
crawler.crawl(spider)
crawler.start()
log.start()
reactor.run() # the script will block here
于 2013-08-02T11:04:52.513 に答える