0

Hi everyone,

I am new to here, I am currently working on my own project, I want to automatically request a website eg. www.example.com, then there are some specific buttons to click and to fill with the text I want (like a auto post) in Javascript.

currently I have tried some code to request the url, it comes up with CORS problem.

var theSite = new XMLHttpRequest();
var theUrl = "www.example.com";
function loadPage(){
  theSite.addEventListener("readystatechange", autopost, false);
  theSite.open('GET', theUrl, true);
  theSite.send();
}

Question:

  1. How to solve the CORS problem?
  2. Does "theSite" contains the entire DOM from the url?
  3. if Yes, then can use getElementByID() from "theSite"?

Thanks for the help.

  • 1
    Possible duplicate of [Why does my JavaScript get a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error when Postman does not?](https://stackoverflow.com/questions/20035101/why-does-my-javascript-get-a-no-access-control-allow-origin-header-is-present) – Patrick Hund Dec 02 '17 at 15:55
  • You will need to scrape the site html server-side. Client side requests will give CORS errors – posit labs Dec 02 '17 at 15:58

1 Answers1

0

Looks like you want to automate form submission. There are tools which can do this for you. As you mentioned JavaScript. Take a look at puppeteer, a node library to control headless chrome.

Pranay Kumar
  • 2,139
  • 1
  • 15
  • 15