这是我的代码如下-
import scrapy
from scrapy.http import Request
class lyricsFetch(scrapy.Spider):
name = "lyricsFetch"
allowed_domains = ["metrolyrics.com"]
print "\nEnter the name of the ARTIST of the song for which you want the lyrics for. Minimise the spelling mistakes, if possible."
artist_name = raw_input('>')
print "\nNow comes the main part. Enter the NAME of the song itself now. Again, try not to have any spelling mistakes."
song_name = raw_input('>')
artist_name = artist_name.replace(" ", "_")
song_name = song_name.replace(" ","_")
first_letter = artist_name[0]
print artist_name …Run Code Online (Sandbox Code Playgroud) 我在 Windows 7 的 python 2.7 环境中安装了 Scrapy,但是当我尝试使用scrapy startproject newProject命令提示符启动一个新的 Scrapy 项目时,显示此消息
'scrapy' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)
笔记:
在 Raspberry Pi 3 上运行 scrapy 时收到错误。
我已经成功安装了它,但是当我尝试使用之前创建的蜘蛛启动项目或爬行时,出现以下错误:
Traceback (most recent call last):
File "/usr/local/bin/scrapy", line 7, in <module>
from scrapy.cmdline import execute
File "/usr/local/lib/python3.4/dist-packages/scrapy/cmdline.py", line 9, in <module>
from scrapy.crawler import CrawlerProcess
File "/usr/local/lib/python3.4/dist-packages/scrapy/crawler.py", line 7, in <module>
from twisted.internet import reactor, defer
File "/usr/local/lib/python3.4/dist-packages/twisted/internet/reactor.py", line 38, in <module>
from twisted.internet import default
File "/usr/local/lib/python3.4/dist-packages/twisted/internet/default.py", line 56, in <module>
install = _getInstallFunction(platform)
File "/usr/local/lib/python3.4/dist-packages/twisted/internet/default.py", line 44, in _getInstallFunction
from twisted.internet.epollreactor import install
File "/usr/local/lib/python3.4/dist-packages/twisted/internet/epollreactor.py", line 24, in <module>
from …Run Code Online (Sandbox Code Playgroud) 我正在用 Scrapy 运行一个蜘蛛,但在它完成爬行后,它似乎无法终止。日志统计只是递归地报告它正在抓取 0 页/分钟。当我尝试使用 Ctrl-C 退出时,它无法正常关闭,我必须再次使用 Ctrl-C 强制退出。任何线索发生了什么?
完成刮擦后,我只是得到这样的输出:
2017-08-24 11:13:45 [scrapy.extensions.logstats] 信息:抓取 60 页(以 0 页/分钟),抓取 54 个项目(以 0 项/分钟)
2017-08-24 11:14:45 [scrapy.extensions.logstats] 信息:抓取 60 页(以 0 页/分钟),抓取 54 个项目(以 0 项/分钟)
2017-08-24 11:15:45 [scrapy.extensions.logstats] 信息:抓取 60 页(以 0 页/分钟),抓取 54 个项目(以 0 项/分钟)
2017-08-24 11:16:45 [scrapy.extensions.logstats] 信息:抓取 60 页(以 0 页/分钟),抓取 54 个项目(以 0 项/分钟)
2017-08-24 11:17:45 [scrapy.extensions.logstats] 信息:抓取 60 页(以 0 页/分钟),抓取 54 个项目(以 0 项/分钟)
2017-08-24 11:18:45 [scrapy.extensions.logstats] 信息:抓取 60 页(以 0 页/分钟),抓取 54 个项目(以 …
是否可以使用 Scrapy 生成网站的站点地图,包括每个页面的 URL 及其级别/深度(我需要从主页遵循的链接数量)?站点地图的格式不必是 XML,它只是关于信息。此外,我想保存被抓取页面的完整 HTML 源代码以供进一步分析,而不是仅从中抓取某些元素。
有使用 Scrapy 经验的人能否告诉我这是否是 Scrapy 可能/合理的场景,并给我一些有关如何查找说明的提示?到目前为止,我只能找到更复杂的场景,但没有解决这个看似简单的问题的方法。
经验丰富的网络爬虫的插件:鉴于它是可能的,你认为 Scrapy 甚至是合适的工具吗?或者使用请求等库编写自己的爬虫会更容易吗?
我想在不同的域下获取网页,这意味着我必须在命令"scrapy crawl myspider"下使用不同的蜘蛛.但是,由于网页内容不同,我必须使用不同的管道逻辑将数据放入数据库.但对于每个蜘蛛,它们必须遍历settings.py中定义的所有管道.是否有其他优雅的方法为每个蜘蛛使用单独的管道?
我已成功废弃单个帐户的数据.我想在一个网站上废弃多个帐户,多个帐户需要多次登录,我想要一种如何管理登录/注销的方法?
我刚开始学习scrapy.所以我按照scrapy文档.我刚写了那个网站上提到的第一个蜘蛛.
import scrapy
class DmozSpider(scrapy.Spider):
name = "dmoz"
allowed_domains = ["dmoz.org"]
start_urls = [
"http://www.dmoz.org/Computers/Programming/Languages/Python/Books/",
"http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/"
]
def parse(self, response):
filename = response.url.split("/")[-2]
with open(filename, 'wb') as f:
f.write(response.body)
Run Code Online (Sandbox Code Playgroud)
在scrapy crawl dmoz项目的根目录上运行此命令后,它会显示以下错误.
2015-06-07 21:53:06+0530 [scrapy] INFO: Scrapy 0.14.4 started (bot: tutorial)
2015-06-07 21:53:06+0530 [scrapy] DEBUG: Enabled extensions: LogStats, TelnetConsole, CloseSpider, WebService, CoreStats, MemoryUsage, SpiderState
Traceback (most recent call last):
File "/usr/bin/scrapy", line 4, in <module>
execute()
File "/usr/lib/python2.7/dist-packages/scrapy/cmdline.py", line 132, in execute
_run_print_help(parser, _run_command, cmd, args, …Run Code Online (Sandbox Code Playgroud) 我正在使用一个简单的CrawlSpider实现来抓取网站.默认情况Scrapy下,302重定向到目标位置,并忽略最初请求的链接.在特定网站上,我遇到了一个302重定向到另一个页面的页面.我的目标是记录原始链接(响应302)和目标位置(在HTTP响应头中指定)并在parse_item方法中处理它们CrawlSpider.请指导我,我该怎么做到这一点?
我碰到的解决方案提的使用dont_redirect=True或REDIRECT_ENABLE=False,但我真的不希望忽略重定向,其实我也想看看(即不能忽视)重定向页面为好.
例如:我访问http://www.example.com/page1哪个发送302重定向HTTP响应并重定向到http://www.example.com/page2.默认情况下,scrapy忽略page1,跟随page2并处理它.我想同时处理page1和page2在parse_item.
编辑
我已经handle_httpstatus_list = [500, 404]在蜘蛛的类定义中使用来处理500和404响应代码parse_item,但302如果我在其中指定它,则同样不起作用handle_httpstatus_list.
我试图通过Scrapy刮掉亚马逊.但我有这个错误
DEBUG: Retrying <GET http://www.amazon.fr/Amuses-bouche-Peuvent-b%C3%A9n%C3%A9ficier-dAmazon-Premium-Epicerie/s?ie=UTF8&page=1&rh=n%3A6356734031%2Cp_76%3A437878031>
(failed 1 times): 503 Service Unavailable
Run Code Online (Sandbox Code Playgroud)
我认为这是因为=亚马逊非常擅长检测机器人.我该如何防止这种情况?
我time.sleep(6)在每次请求之前使用 过.
我不想使用他们的API.
我试过用tor和polipo
scrapy ×10
scrapy-spider ×10
python ×7
web-scraping ×4
web-crawler ×3
python-2.7 ×2
amazon ×1
raspberry-pi ×1
redirect ×1
response ×1