SelectBy.Script

Questions & Answers about Helium Scraper 3
Post Reply
cindyh
Posts: 2
Joined: Fri Nov 29, 2019 1:53 am

SelectBy.Script

Post by cindyh » Fri Nov 29, 2019 2:04 am

I think it's easiest to find my selections by Javascript and regex. But I don't see an example of what a SelectBy.Script should look like. Woud this be legitimate (I would eventually replace the innerText assignment with a regex replce).

Code: Select all

SelectBy.Script
   ·  "var s=createElement(\"p\");s.innerText='description'; return s;"
And the escaping of \\ seems to be weird when I've tried it (I need to look for the \ character in my regex, which escapes as \\ in my regex, and that becomes \\\\ in the SelectBy.Script string????

Cindy

doncorleone
Posts: 3
Joined: Thu May 30, 2019 5:49 pm

Re: Select.ByScript

Post by doncorleone » Fri Nov 29, 2019 4:26 pm

It'd be easier if you add your script to Scripting > Scripts in project explorer and then did

Code: Select all

SelectBy.Script
   ·  Script.MyScript
That way you won't need to add any extra escape characters plus you'll get code completion. Your script should work and select the element you're creating but not sure why you'd want to create an element and then select it?

cindyh
Posts: 2
Joined: Fri Nov 29, 2019 1:53 am

Re: Select.ByScript

Post by cindyh » Sun Dec 01, 2019 5:37 pm

Do I have to create an element, or can I just return a string from the page slected by regex? That was my goal - to put in the text of that element a regex selection from the content on the page. The documentation says your byscript has to return "an element", so I didnt know if that was a DOM element, or simply a string value would do.

webmaster
Site Admin
Posts: 494
Joined: Mon Dec 06, 2010 8:39 am
Contact:

Re: Select.ByScript

Post by webmaster » Mon Dec 02, 2019 5:22 pm

Yes, Select.ByScript must return a DOM element or a list of DOM elements. I guess the documentation should be explicit about this. If you just need to get a string from a script, you can use Browser.EvalScript like this:

Code: Select all

Browser.EvalScript
   ·  "return 'Hello World!';"
   ·  0
as myString
extract
   test
      myString
Juan Soldi
The Helium Scraper Team

Post Reply