Open Auditor21496 opened 3 years ago
I want to use splash to click on this button ( Trước) but when i run the code the page still stayed the same. Can anyone know what is wrong with my code.
`import scrapy from scrapy_splash import SplashRequest
class CafefSpiderSpider(scrapy.Spider): name = 'cafef_spider' allowed_domains = ['s.cafef.vn'] start_urls = ['http://s.cafef.vn/hose/PPC-cong-ty-co-phan-nhiet-dien-pha-lai.chn']
def start_requests(self): filters_script = """function main(splash) splash.plugins_enabled = true assert(splash:go(splash.args.url)) splash:wait(10) local get_element_dim_by_xpath = splash:jsfunc([[ function(xpath) { var element = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; var element_rect = element.getClientRects()[0]; return {"x": element_rect.left, "y": element_rect.top} } ]]) -- back one quarter local make_dimensions = get_element_dim_by_xpath( '//*[contains(text(),"Theo năm")]') splash:set_viewport_full() splash:mouse_click(make_dimensions.x, make_dimensions.y) splash:wait(5) return splash:html() end""" yield SplashRequest(url='http://s.cafef.vn/hose/PPC-cong-ty-co-phan-nhiet-dien-pha-lai.chn', endpoint='execute', callback=self.parse, args={'lua_source': filters_script} ) def parse(self, response): data = response.xpath('//*[contains(text(),"6,235,981")]/text()').extract() print(data)
`
I want to use splash to click on this button ( Trước) but when i run the code the page still stayed the same. Can anyone know what is wrong with my code.
`import scrapy from scrapy_splash import SplashRequest
class CafefSpiderSpider(scrapy.Spider): name = 'cafef_spider' allowed_domains = ['s.cafef.vn'] start_urls = ['http://s.cafef.vn/hose/PPC-cong-ty-co-phan-nhiet-dien-pha-lai.chn']
`