给出了从代码中运行scrapy爬虫的许多方法:
import scrapy
from scrapy.crawler import CrawlerProcess
class MySpider(scrapy.Spider):
# Your spider definition
...
process = CrawlerProcess({
'USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'
})
process.crawl(MySpider)
process.
我对python和线程都是新手。我已经编写了python代码,作为一个网络爬虫和搜索网站的特定关键字。我的问题是,如何使用线程同时运行我的类的三个不同的实例。当其中一个实例找到关键字时,所有三个实例都必须关闭并停止在web上爬行。下面是一些代码。
class Crawler:
def __init__(self):
# the actual code for finding the keyword
def main():
Crawl = Crawler()
if __name__ == "__main__":