Python 使用Scrapy和Splash抓取javascript内容
我正在使用scrapy和splash删除此链接: 但我无法提取数据 我的代码:Python 使用Scrapy和Splash抓取javascript内容,python,scrapy,scrapy-splash,Python,Scrapy,Scrapy Splash,我正在使用scrapy和splash删除此链接: 但我无法提取数据 我的代码: import scrapy from scrapy_splash import SplashRequest class ManuPySpider(scrapy.Spider): name = 'manulife' def start_requests(self): yield SplashRequest( url = 'https://manulife.taleo.net
import scrapy
from scrapy_splash import SplashRequest
class ManuPySpider(scrapy.Spider):
name = 'manulife'
def start_requests(self):
yield SplashRequest(
url = 'https://manulife.taleo.net/careersection/external_global/jobsearch.ftl?lang=en&location=1038',
callback=self.parse,
)
def parse(self, response):
yield{
'demo' : response.css('div.absolute > span > a::text').extract()
}
Setting.py:
BOT_NAME = 'manulife'
SPIDER_MODULES = ['manulife.spiders']
NEWSPIDER_MODULE = 'manulife.spiders'
DOWNLOADER_MIDDLEWARES = {
'scrapy_splash.SplashCookiesMiddleware': 723,
'scrapy_splash.SplashMiddleware': 725,
'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware':
810,
}
SPLASH_URL = 'http://192.168.99.100:8050'
SPIDER_MIDDLEWARES = {
'scrapy_splash.SplashDeduplicateArgsMiddleware': 100,
}
DUPEFILTER_CLASS = 'scrapy_splash.SplashAwareDupeFilter'
HTTPCACHE_STORAGE = 'scrapy_splash.SplashAwareFSCacheStorage'
# Obey robots.txt rules
ROBOTSTXT_OBEY = True
我已经检查了我的水花是否启动并运行。它可能有什么问题
感谢当我试图通过Splash console(在
8050
端口)使用默认设置呈现页面时,它没有包含所需的数据(即搜索结果表为空)。但是一旦我增加了wait
参数,它就起作用了。因此,尝试增加参数:
yield SplashRequest(
url = 'https://manulife.taleo.net/careersection/external_global/jobsearch.ftl?lang=en&location=1038',
callback=self.parse, args={'wait': 5}
)
当我试图通过Splash控制台(在
8050
port上)使用默认设置呈现页面时,它没有包含所需的数据(即搜索结果表为空)。但是一旦我增加了wait
参数,它就起作用了。因此,尝试增加参数:
yield SplashRequest(
url = 'https://manulife.taleo.net/careersection/external_global/jobsearch.ftl?lang=en&location=1038',
callback=self.parse, args={'wait': 5}
)
太好了,这对我很有效。顺便问一下,这背后的原因是什么?网站呈现数据的速度慢吗?该参数由
wait
参数设置,允许呈现引擎在页面加载后处理页面。如果内容被更新,比如JavaScript,这需要一些时间。这对我来说很好。顺便问一下,这背后的原因是什么?网站呈现数据的速度慢吗?该参数由wait
参数设置,允许呈现引擎在页面加载后处理页面。如果内容由JavaScript等更新,有时需要这样做,这需要一些时间。