Search code examples
python-3.xweb-scrapingscrapyscrapy-splash

Scrapy Splash: clicking the button doesn't open next page


I am having trouble to execute the Click Button with Scrapy-Splash. The website I am trying to scrape is this one: https://search.siemens.com/en/?q=iot&lr=lang_en&as_oq=&as_sitesearch=&site=siemens_c_ww&client=siemens_f_ww&getfields=%2A&proxystylesheet=p_ia&queryString=lang%3Den%26site%3Dsiemens_c_ww%26q%3Diot%26lr%3Dlang_en%26collapse%3Dtrue%26class%3Dsearch%2Cbanner%2Ctext%26_charset%3DUTF-8&start=10&hl=en&access=p&filter=1&output=xml_no_dtd&sort=date%253AD%253AL%253Ad1&oe=UTF-8&ie=UTF-8&exclude_apps=1&ud=1&sheet=0

I am using the following script:

function main(splash, args)
  assert(splash:go(args.url))
  assert(splash:wait(0.5))
  assert(splash:runjs('document.querySelector(".next a[href]").click()'))
  splash:set_viewport_full()
  return {
    html = splash:html(),
    png = splash:png(),
    har = splash:har(),
  }
end

When executed I get back the first page and not the next one. The click button manually works. I tried using mouse_click() with the same result. Thank you for more ideas to solve this problem :)


Solution

  • I think you need to wait some delay time after button is clicked. Splash need time to re render dynamic page