Created
May 26, 2020 12:48
-
-
Save rafikahmed/70a38deb6ff11c2ad02173db6689d1a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MySpider(scrapy.Spider): | |
name = 'example' | |
current_page = 1 | |
script = ''' | |
function main(splash, args) | |
splash.private_mode_enabled = false | |
url = args.url | |
assert(splash:go(url)) | |
assert(splash:wait(1)) | |
assert(splash:run_js(args.js_source)) | |
assert(splash:wait(1)) | |
return splash:html() | |
end | |
''' | |
def start_requests(self): | |
# initial request | |
def parse(self, response): | |
# parse your data | |
#pagination | |
if self.current_page <= 5: | |
self.current_page += 1 | |
js_source = f"javascript:__doPostBack('ctl00$MainContent$gvReport','Page${self.current_page}')" | |
yield SplashRequest(url='YOUR_URL', callback=self.parse, endpoint='execute', args={'lua_source': self.script, 'js_source':js_source}, dont_filter=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function main(splash, args) | |
splash.private_mode_enabled = false | |
url = args.url | |
assert(splash:go(url)) | |
assert(splash:wait(1)) | |
assert(splash:run_js(args.js_source)) | |
assert(splash:wait(1)) | |
return splash:html() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trying to loop through multiple stock but they get mixed together
`
import scrapy
from scrapy_splash import SplashRequest
class StockQrSpider(scrapy.Spider):
`