1

I'm trying to make a web-scraper in Node JS and I've hit a roadblock. I need to click on a button BUT, if I'm not mistaken, Node doesn't actually render the web-page like a browser would so I can't use a selector or X-Path.

How then, could I click a specific button with the value "yes" if I can't use the selector or X-path? There's no id unique to only the yes button.

I'm asking this because I want to parse a specific web-page but I get redirected to a page that asks me to press two buttons. Pressing 'Yes' will bring me to the page I want. Pressing 'No' will obviously stop me from going forward.

Is there any way to do what I want within the confines on Node without having to resort to something like JSDOM?

Here's part of the HTML i'm working with:

<div class="buttons">
<button class="c-btn c-btn-primary" type="submit" name="bigbutton" value="no">no thank you</button>
<button class="c-btn c-btn-primary" type="submit" name="bigbutton" value="yes">continue</button>
</div>

I tried using something like this:

document.getElementByID("selector").click()

but was returned with 'ReferenceError: document is not defined'.

7
  • Possible duplicate of Why doesn't node.js have a native DOM? Commented Apr 12, 2016 at 1:53
  • 3
    You can't really "click" anything when dealing with scraped content on a webserver, maybe you wanted a headless browser or a bot instead Commented Apr 12, 2016 at 1:54
  • Is it possible to simply find out the URL of the redirected page beforehand and have Node scrap it directly? Commented Apr 12, 2016 at 2:43
  • If I make a request to go to url X it instantly redirects me to page Y, which is what we have here, two buttons. Clicking continue brings me to the page X i wanted to go to. I have a script written for the data parsing when I actually land on page X but can't seem to get past Y without clicking continue. Commented Apr 12, 2016 at 2:48
  • So I figured out I can't even get past the page itself if I disable cookies- Is there a way to add a cookie that works to my node script so that it clears through? Commented Apr 12, 2016 at 5:08

1 Answer 1

1

Have you tried to use Zombie? I've used and worked well! This link is very helpful, since clarify quickly how to perform actions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.