单击链接弹出通知后会出现一个页面。因此,要按照链接lua脚本应单击按钮1,然后单击按钮2(在弹出通知上接受),然后继续下一页。我的脚本没有点击按钮2.我错在哪里?
class PalmBeachSpider(scrapy.Spider):
name ='splash'
custom_settings = {
'SPLASH_URL' : 'http://localhost:8050',
'DOWNLOADER_MIDDLEWARES' : {
'scrapy_splash.SplashCookiesMiddleware': 723,
'scrapy_splash.SplashMiddleware': 725,
'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware': 810,
},
'SPIDER_MIDDLEWARES' : {
'scrapy_splash.SplashDeduplicateArgsMiddleware': 100,
}
}
script = '''
function main(splash, args)
assert(splash:go(args.url))
assert(splash:wait(0.5))
assert(splash:runjs('document.querySelector("#bodySection > div > div > div:nth-child(7) > div > div:nth-child(2) > a").click()'))
assert(splash:wait(3.5))
assert(splash:runjs('document.querySelector("a#idAcceptYes").click()'))
return {
html = splash:html(),
}
end'''
def start_requests(self):
url = 'https://apps.stjohnsclerk.com/Landmark'
yield SplashRequest(url = url, callback = self.parse, endpoint = 'execute', args={'wait': 0.5, 'lua_source' : self.script})
def parse(self, response):
inspect_response(response, self)
response = HtmlResponse(url=response.url, body=response.data['html'], encoding = 'utf-8')
你可以在最后一次启动后添加另一个'assert(splash:wait(...)):runjs。