Scrapy爬虫不稳定,有时能用有时不行
Scrapy crawler unstable, sometimes works sometimes won't
我的抓取工具有时会工作 - 抓取和抓取但有时只是抓取并且不会抓取任何东西,除非我对代码进行任何更改:/我不明白。没有错误代码或任何东西。不刮的时候是这个样子的;
2017-02-05 23:52:00 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.amazon.com/s/srs=9187220011&rh=n%3A283155> (referer: None)
2017-02-05 23:52:00 [scrapy.core.engine] INFO: Closing spider (finished)
2017-02-05 23:52:00 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 712,
'downloader/request_count': 2,
'downloader/request_method_count/GET': 2,
'downloader/response_bytes': 3964,
'downloader/response_count': 2,
'downloader/response_status_count/200': 2,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2017, 2, 6, 5, 52, 0, 552000),
'log_count/DEBUG': 7,
'log_count/INFO': 7,
'log_count/WARNING': 1,
'response_received_count': 2,
'scheduler/dequeued': 1,
'scheduler/dequeued/memory': 1,
'scheduler/enqueued': 1,
'scheduler/enqueued/memory': 1,
'start_time': datetime.datetime(2017, 2, 6, 5, 51, 59, 328000)}
我正在尝试抓取该网站并使用 mongodb 管道将其放入 mongodb。好像它确实有效,但有时它不起作用,这很奇怪。
我在想这可能是管道问题,但不确定..有什么建议吗?我怎样才能检查出什么问题。我连接到 mongodb,就像我在做这个 mongod 是 运行
这是我的mongodb管道;
class MongoDBPipeline(object):
def __init__(self):
connection = pymongo.MongoClient(
settings['MONGODB_SERVER'],
settings['MONGODB_PORT']
)
db = connection[settings['MONGODB_DB']]
self.collection = db[settings['MONGODB_COLLECTION']]
def process_item(self, item, spider):
valid = True
for data in item:
if not data:
valid = False
raise DropItem("Missing {0}!".format(data))
if valid:
self.collection.insert(dict(item))
log.msg("link added to MongoDB database!",
level=log.DEBUG, spider=spider)
return item
先生,您正在抓取 Amazon,一个非常著名的 anti-crawler 网站。
这是因为有时他们会向您发送回复,但有时由于连续请求而不是实际网页,他们只显示验证码。
为了顺利抓取亚马逊,您将不得不使用代理,即使使用代理,您也会看到很多验证码,但您必须重试那些获得验证码的 URL。
你可以用这段代码看看页面是否有验证码
if response.css('#captchacharacters').extract_first():
print("Captcha found ")
我的抓取工具有时会工作 - 抓取和抓取但有时只是抓取并且不会抓取任何东西,除非我对代码进行任何更改:/我不明白。没有错误代码或任何东西。不刮的时候是这个样子的;
2017-02-05 23:52:00 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.amazon.com/s/srs=9187220011&rh=n%3A283155> (referer: None)
2017-02-05 23:52:00 [scrapy.core.engine] INFO: Closing spider (finished)
2017-02-05 23:52:00 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 712,
'downloader/request_count': 2,
'downloader/request_method_count/GET': 2,
'downloader/response_bytes': 3964,
'downloader/response_count': 2,
'downloader/response_status_count/200': 2,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2017, 2, 6, 5, 52, 0, 552000),
'log_count/DEBUG': 7,
'log_count/INFO': 7,
'log_count/WARNING': 1,
'response_received_count': 2,
'scheduler/dequeued': 1,
'scheduler/dequeued/memory': 1,
'scheduler/enqueued': 1,
'scheduler/enqueued/memory': 1,
'start_time': datetime.datetime(2017, 2, 6, 5, 51, 59, 328000)}
我正在尝试抓取该网站并使用 mongodb 管道将其放入 mongodb。好像它确实有效,但有时它不起作用,这很奇怪。 我在想这可能是管道问题,但不确定..有什么建议吗?我怎样才能检查出什么问题。我连接到 mongodb,就像我在做这个 mongod 是 运行
这是我的mongodb管道;
class MongoDBPipeline(object):
def __init__(self):
connection = pymongo.MongoClient(
settings['MONGODB_SERVER'],
settings['MONGODB_PORT']
)
db = connection[settings['MONGODB_DB']]
self.collection = db[settings['MONGODB_COLLECTION']]
def process_item(self, item, spider):
valid = True
for data in item:
if not data:
valid = False
raise DropItem("Missing {0}!".format(data))
if valid:
self.collection.insert(dict(item))
log.msg("link added to MongoDB database!",
level=log.DEBUG, spider=spider)
return item
先生,您正在抓取 Amazon,一个非常著名的 anti-crawler 网站。
这是因为有时他们会向您发送回复,但有时由于连续请求而不是实际网页,他们只显示验证码。
为了顺利抓取亚马逊,您将不得不使用代理,即使使用代理,您也会看到很多验证码,但您必须重试那些获得验证码的 URL。
你可以用这段代码看看页面是否有验证码
if response.css('#captchacharacters').extract_first():
print("Captcha found ")