草庐IT

python - 我如何告诉 Scrapy 只抓取 Xpath 中的链接?

我是Scrapy的新手,我想做的是制作一个爬虫,它只会跟踪给定start_urls上HTML元素内的链接举个例子,假设我只是想让一个爬虫通过start_urls设置为https://www.airbnb.com/s?location=New+York%2C+NY&checkin=&checkout=&guests=1的AirBnB房源。我不想抓取URL中的所有链接,我只想抓取xpath中的链接//*[@id="results"]目前我正在使用下面的代码来抓取所有的链接,我怎样才能让它只抓取//*[@id="results"]fromscrapy.selectorimportHtmlXP

python - 如何将 scrapy 爬虫的数据保存到变量中?

我目前正在构建一个网络应用程序,用于显示scrapy蜘蛛收集的数据。用户发出请求,蜘蛛抓取一个网站,然后将数据返回给应用程序以便得到提示。我想直接从scraper检索数据,而不依赖于中间.csv或.json文件。像这样的东西:fromscrapy.crawlerimportCrawlerProcessfromscraper.spidersimportMySpiderurl='www.example.com'spider=MySpider()crawler=CrawlerProcess()crawler.crawl(spider,start_urls=[url])crawler.star

python - Scrapy 重试或重定向中间件

在使用scrapy爬取网站时,大约有1/5的时间我被重定向到用户阻止的页面。当发生这种情况时,我丢失了从重定向的页面。我不知道要使用哪个中间件或在该中间件中使用什么设置,但我想要这个:调试:从(GEThttp://domain.com/bar.htm)重定向(302)到(GEThttp://domain.com/foo.aspx)不要删除bar.htm。当抓取器完成时,我最终没有来自bar.htm的数据,但我正在轮换代理,所以如果它再次尝试bar.htm(可能再试几次),我应该得到它。如何设置尝试次数?如果重要的话,我只允许爬虫使用一个非常具体的起始url,然后只跟随“下一页”链接,所

python - 如何从无限滚动网站上抓取所有内容?抓取

我正在使用scrapy。我正在使用的网站具有无限滚动功能。该网站有很多帖子,但我只抓取了13个。如何抓取剩余的帖子?这是我的代码:classexampleSpider(scrapy.Spider):name="example"#from_date=datetime.date.today()-datetime.timedelta(6*365/12)allowed_domains=["example.com"]start_urls=["http://www.example.com/somethinghere/"]defparse(self,response):forhrefinrespon

python - Scrapy 中间件顺序

碎片documentation说:thefirstmiddlewareistheoneclosertotheengineandthelastistheoneclosertothedownloader.TodecidewhichordertoassigntoyourmiddlewareseetheDOWNLOADER_MIDDLEWARES_BASEsettingandpickavalueaccordingtowhereyouwanttoinsertthemiddleware.Theorderdoesmatterbecauseeachmiddlewareperformsadifferen

python - Scrapy 的 Scrapyd 调度蜘蛛太慢

我正在运行Scrapyd,同时启动4个爬虫时遇到了一个奇怪的问题。2012-02-0615:27:17+0100[HTTPChannel,0,127.0.0.1]127.0.0.1--[06/Feb/2012:14:27:16+0000]"POST/schedule.jsonHTTP/1.1"20062"-""python-requests/0.10.1"2012-02-0615:27:17+0100[HTTPChannel,1,127.0.0.1]127.0.0.1--[06/Feb/2012:14:27:16+0000]"POST/schedule.jsonHTTP/1.1"200

python - LinkExtractor 和 SgmlLinkExtractor 的区别

我是scrapy框架的新手,我看过一些使用LinkExtractors的教程和一些使用SgmlLinkExtractor的教程。我曾尝试寻找两者的差异/利弊,但结果并不令人满意。谁能告诉我两者的区别?我们什么时候应该使用上述提取器?谢谢! 最佳答案 为什么您找不到对SgmlLinkExtractor的引用的问题是它现在已弃用(相关changeset)。您可以找到SgmlLinkExtractor定义here-在Scrapy0.24文档中。而且,你不应该再使用SgmlLinkExtractor-Scrapy现在只留下一个链接提取器-L

python - Scrapy csv 文件有统一的空行?

这是蜘蛛:importscrapyfromdanmurphys.itemsimportDanmurphysItemclassMySpider(scrapy.Spider):name='danmurphys'allowed_domains=['danmurphys.com.au']start_urls=['https://www.danmurphys.com.au/dm/navigation/navigation_results_gallery.jsp?params=fh_location%3D%2F%2Fcatalog01%2Fen_AU%2Fcategories%3C%7Bcatal

python - 启动 scrapy shell 时如何禁用 robots.txt?

我在几个网站上使用Scrapyshell没有问题,但是当机器人(robots.txt)不允许访问网站时我发现了问题。如何禁用Scrapy的机器人检测(忽略存在)?先感谢您。我说的不是Scrapy创建的项目,而是Scrapyshell命令:scrapyshell'www.example.com' 最佳答案 在您的scrapy项目的settings.py文件中,查找ROBOTSTXT_OBEY并将其设置为False。 关于python-启动scrapyshell时如何禁用robots.txt

python - 如何在Python3.6和CentOs上安装Twisted + Scrapy

我在Centos7上使用最新的Python和专用的virtualenv(ENV)[luoc@study~]$lsb_release-aLSBVersion::core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarchDistributorID:CentOSDescription:CentOSLin