我已经成功地使用scrapy-splash加载javascript生成的html。现在我想设置一些不属于表单的输入值。只要我输入一个值,网站上的内容就会发生变化。我还没有找到设置输入值的方法并重新调整调整后的html。这可能吗?
class ExampleSpider(scrapy.Spider):
name = "example"
allowed_domains = ["example.com"]
start_urls = (
'https://example.com',
)
def start_requests(self):
for url in self.start_urls:
yield scrapy.Request(url, self.parse, meta={
'splash': {
'endpoint': 'render.html',
'args': {'wait': 3}
}
})
def parse(self, response):
page = response.url.split("/")[-2]
filename = 'screener-%s.html' % page
with open(filename, 'wb') as f:
f.write(response.body)
self.log('Saved file %s' % filename)
答案 0 :(得分:1)
您需要按照评论中的建议将输入放在lua_script中,按照示例单击按钮:
Illuminate\Database\Seeder::call
然后像这样执行脚本:
script ="""
function main(splash)
local url = splash.args.url
assert(splash:go(url))
assert(splash:runjs('document.getElementsByClassName("nameofbutton").click()'))
assert(splash:wait(0.75))
-- return result as a JSON object
return {
html = splash:html()
}
end
"""