gpt4 book ai didi

scrapy - 如何在 Scrapy Splash 中加载本地 HTML 文件?

转载 作者:行者123 更新时间:2023-12-03 14:53:47 25 4
gpt4 key购买 nike

我想使用 Scrapy Splash 加载本地 HTML 文件并将其另存为 PNG/JPEG,然后删除该 HTML 文件

script = """
splash:go(args.url)
return splash:png()
"""
resp = requests.post('http://localhost:8050/run', json={
'lua_source': script,
'url': 'file://my_file.html'
})
resp.content

它返回我

Failed loading page (Protocol "" is unknown) Network error #301



我也试过
yield SplashRequest(url=filepath, 
callback=self.parse_result,
meta={'filepath': filepath},
args={
'wait': 0.5,
'png': 1,
},
endpoint='render.html',
)

但我得到

2020-04-23 12:07:41 [scrapy.downloadermiddlewares.retry] DEBUG: Retrying http://localhost:8050/render.html> (failed 1 times): 502 Bad Gateway

最佳答案

不建议通过底部两个链接使用localhost。有些人提到关闭 Crawlera 解决了他们的问题。它可能试图通过在线 IP 路由您的请求以到达您的本地主机,这将是有问题的。
Scrapy Splash on Ubuntu server: got an unexpected keyword argument 'encoding'
https://github.com/scrapy-plugins/scrapy-splash/issues/108

关于scrapy - 如何在 Scrapy Splash 中加载本地 HTML 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61386892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com