Start a new topic
Answered

Javascript injection in Splash?

Hi. I'm trying to learn Scrapy-Splash. Within the below Splash lua script, the png returned does not show the updated element.

The javascript does work in Chrome Dev Tools. 

Any push in the right direction is appreciated.

    

function main(splash, args)
  assert(splash:go("https://news.ycombinator.com/"))
  splash:runjs([[
  el = document.evaluate('//b[@class="hnname"]',document, null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
  if (el != null) {
      el.textContent = 'Javascript Injection';
  }
  ]])
	 return {png=splash:png()}
end

 

    




Best Answer

Hello, 


I understand that there was a Support ticket for this issue and Javascript Injection can be done through splash through js_source  https://splash.readthedocs.io/en/stable/api.html#executing-custom-javascript-code-within-page-context

1 Comment

Answer

Hello, 


I understand that there was a Support ticket for this issue and Javascript Injection can be done through splash through js_source  https://splash.readthedocs.io/en/stable/api.html#executing-custom-javascript-code-within-page-context

Login to post a comment