使用 scrapy splash 渲染 js 页面时出现的问题
2017-12-17 22:32:38
收藏:0
阅读:95
评论:1
我在使用带有动态加载内容的网页进行爬取时遇到了问题。我使用了以下命令运行了 splash docker 镜像:
docker run -p 8050:8050 scrapinghub/splash --disable-private-mode
我的 scrapy-splash spider 使用一个 LUA 脚本,它应该滚动并返回完整页面的 HTML:
import scrapy
from scrapy_splash import SplashRequest
class MySplashSpider(scrapy.Spider):
# requires the scrapy-splash docker image running
name = "psplash"
def __init__(self):
self.domain = 'http://www.phillips.com'
self.user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0) Gecko/20100101 Firefox/10.0"
self.script = """
function main(splash)
local num_scrolls = 3
local scroll_delay = 1.0
splash:set_viewport_full()
splash:wait(5.0)
return splash:html()
end
"""
self.splash_args = {'lua_source': self.script,
'ua': self.user_agent
}
def start_requests(self):
base_url = "https://www.phillips.com/auctions/past/filter/Department=20TH%20CENTURY%20%26%20CONTEMPORARY%20ART!Editions!Latin%20America!Photographs"
yield SplashRequest(base_url,
callback = self.parse_pagination,
endpoint = 'execute',
args = self.splash_args
)
def parse_pagination(self, response):
print('xxxxxxxxxx', response.xpath("//footer/ul/li[last()-1]/a/text()").extract())
print('xxxxxxxxxx', response.xpath("//h2/a/@href").extract())
当使用 chrome 开发工具进行检查时,我得到了 //footer/ul/li[last()-1]/a/text() 的值为 29
为什么我对 response.xpath 没有得到结果:
[
{"response_text": "hello world", "response_xpath_value": []}
]
控制台输出没有错误信息:
2017-12-16 13:05:16 [scrapy.core.engine] INFO: Spider opened
2017-12-16 13:05:16 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
xxxxxxxxxx []
xxxxxxxxxx []
2017-12-16 13:05:21 [scrapy.core.engine] INFO: Closing spider (finished)
2017-12-16 13:05:21 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 986,
'downloader/request_count': 1,
'downloader/request_method_count/POST': 1,
'downloader/response_bytes': 163,
'downloader/response_count': 1,
'downloader/response_status_count/200': 1,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2017, 12, 16, 12, 5, 21, 707451),
'log_count/INFO': 7,
'log_count/WARNING': 1,
'response_received_count': 1,
'scheduler/dequeued': 2,
'scheduler/dequeued/memory': 2,
'scheduler/enqueued': 2,
'scheduler/enqueued/memory': 2,
'splash/execute/request_count': 1,
'splash/execute/response_count/200': 1,
'start_time': datetime.datetime(2017, 12, 16, 12, 5, 16, 816927)}
2017-12-16 13:05:21 [scrapy.core.engine] INFO: Spider closed (finished)
我错过了什么?
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

将响应的主体保存为 HTML 文件,然后检查是否按照您的要求下载了完整的页面。如果是,请尝试使用 selectors。