非常新且经验丰富。 我试图从这个URL中删除每个程序名称: https://www.f6s.com/programs?type[]=accelerator&sort=open
当我运行我的scrapy程序时,我一直得到:
2018-05-15 14:26:05 [scrapy.extensions.logstats]信息:抓0页(每分钟0页),抓0件(0件/分)
我的项目目录:
myproject/
scrapy.cfg
__init__.py
items.py
pipelines.py
settings.py
spiders/
__init__.py
byub.py
F6sSpider.py
我的蜘蛛文件:
import scrapy
class CompanySpider(scrapy.Spider):
name = "Company"
def start_requests(self):
urls = [
'https://www.f6s.com/programs?type[]=accelerator&sort=open',
]
for url in urls:
yield scrapy.Request(url=url, callback=self.parse)
def parse(self, response):
for title in response.css('div.title'):
yield {
'program': title.css('div.title a.action.main.no.line::text').extract(),
}
我的日志文件:
2018-05-15 14:20:12 [scrapy.utils.log] INFO: Scrapy 1.5.0 started (bot: myproject)
2018-05-15 14:20:12 [scrapy.utils.log] INFO: Versions: lxml 4.2.1.0, libxml2 2.9.8, cssselect 1.0.3, parsel 1.4.0, w3lib 1.19.0, Twisted 18.4.0, Python 3.6.5 (default, Apr 25 2018, 14:23:58) - [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)], pyOpenSSL 17.5.0 (OpenSSL 1.1.0h 27 Mar 2018), cryptography 2.2.2, Platform Darwin-17.5.0-x86_64-i386-64bit
2018-05-15 14:20:12 [scrapy.crawler] INFO: Overridden settings: {'BOT_NAME': 'myproject', 'NEWSPIDER_MODULE': 'myproject.spiders', 'ROBOTSTXT_OBEY': True, 'SPIDER_MODULES': ['myproject.spiders']}
2018-05-15 14:20:12 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
'scrapy.extensions.telnet.TelnetConsole',
'scrapy.extensions.memusage.MemoryUsage',
'scrapy.extensions.logstats.LogStats']
2018-05-15 14:20:12 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.robotstxt.RobotsTxtMiddleware',
'scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware',
'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware',
'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware',
'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware',
'scrapy.downloadermiddlewares.retry.RetryMiddleware',
'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware',
'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware',
'scrapy.downloadermiddlewares.redirect.RedirectMiddleware',
'scrapy.downloadermiddlewares.cookies.CookiesMiddleware',
'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware',
'scrapy.downloadermiddlewares.stats.DownloaderStats']
2018-05-15 14:20:12 [scrapy.middleware] INFO: Enabled spider middlewares:
['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware',
'scrapy.spidermiddlewares.offsite.OffsiteMiddleware',
'scrapy.spidermiddlewares.referer.RefererMiddleware',
'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware',
'scrapy.spidermiddlewares.depth.DepthMiddleware']
2018-05-15 14:20:12 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2018-05-15 14:20:12 [scrapy.core.engine] INFO: Spider opened
2018-05-15 14:20:12 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2018-05-15 14:20:12 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6023
2018-05-15 14:20:13 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.f6s.com/robots.txt> (referer: None)
2018-05-15 14:20:13 [scrapy.downloadermiddlewares.robotstxt] DEBUG: Forbidden by robots.txt: <GET https://www.f6s.com/programs?type[]=accelerator&sort=open>
2018-05-15 14:20:13 [scrapy.core.engine] INFO: Closing spider (finished)
2018-05-15 14:20:13 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/exception_count': 1,
'downloader/exception_type_count/scrapy.exceptions.IgnoreRequest': 1,
'downloader/request_bytes': 220,
'downloader/request_count': 1,
'downloader/request_method_count/GET': 1,
'downloader/response_bytes': 560,
'downloader/response_count': 1,
'downloader/response_status_count/200': 1,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2018, 5, 15, 13, 20, 13, 614424),
'log_count/DEBUG': 3,
'log_count/INFO': 7,
'memusage/max': 49090560,
'memusage/startup': 49090560,
'response_received_count': 1,
'scheduler/dequeued': 1,
'scheduler/dequeued/memory': 1,
'scheduler/enqueued': 1,
'scheduler/enqueued/memory': 1,
'start_time': datetime.datetime(2018, 5, 15, 13, 20, 12, 874730)}
2018-05-15 14:20:13 [scrapy.core.engine] INFO: Spider closed (finished)
我希望我的终端输出有'Program':'Program Name' 任何帮助将不胜感激!
答案 0 :(得分:0)
robots.txt错误导致您被禁止,因此只需将以下行添加到settings.py
USER_AGENT = 'Mozilla/5.0 (Windows NT 5.2; rv:10.0.1) Gecko/20100101 Firefox/10.0.1 SeaMonkey/2.7.1' # any browser specific user agent will do
ROBOTSTXT_OBEY=False