0

I want to scrawl data from linked In page that comes after login. All I need to do is with pure JavaScript. Below is the code that I'm using to scrawl data.

window.onload = function(){ var request = new XMLHttpRequest();

request.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        console.log(this.responseText);
    }
};

request.open('GET', 'https://www.linkedin.com/sales/home');
request.send();

And I'm getting below error in form of screenshot: Error Screenshot

I also tried to add header request but it didn't work.

Note:  request.open is working against some website's but not all.

Any help will be appreciated. Thanks.

  • The CORS (*Cross Origin Resource Sharing*) error you are getting is something you are unable to control. Originally AJAX request let you pull from any URL, but for security purposes it was changed years ago. So the server (in this case LinkedIn) has to actually have it set up to allow you to connect with AJAX requests. – EssXTee Jan 03 '22 at 13:53
  • Is there any possibility to scrawl data via pure JavaScript? I need to use xmlHTTPRequest because scrawling data will be used for chrome extension. – Tech Thinkbound Jan 03 '22 at 14:07
  • With pure Javascript, no. After the security updates to AJAX/CORS, people used a mixed method that sent the AJAX request to a server script (such as PHP) on their server (the same server your page is on). A PHP script (or pretty much any server side script) can pull the contents of an external URL and then pass it back to the AJAX request. PHP specifically can use things like a **CURL** request or functions like **file_get_contents()**. – EssXTee Jan 03 '22 at 14:25
  • I also tried it with php but linked In login page is not being accessing and showing a message "Sorry, we couldn’t find that page." – Tech Thinkbound Jan 03 '22 at 17:08
  • Same issue and code in link below: https://stackoverflow.com/questions/37040425/logging-into-linkedin-with-php-curl – Tech Thinkbound Jan 03 '22 at 17:10
  • With AJAX alone, this isn't something you can really do. It requires a back-end language running on a server (you mentioned node.js, which also runs on a server). There is a question on Stack Overflow that covers some options for trying to get around the CORS policy when using AJAX requests here: https://stackoverflow.com/questions/15005500/loading-cross-domain-endpoint-with-ajax – EssXTee Jan 03 '22 at 20:14

1 Answers1

0

Your code work really well, but the problem is the destination site "linkedin.com" does not allow you to fetch data. Please take a look at their documentation. https://developer.linkedin.com/

Kopkap
  • 1
  • 2