I have a simple Python code to scrape a web page and it works:
from urllib.request import urlopen
url = "http://www.stackoverflow.com"
html = urlopen(url)
print(html.read())
I want a JavaScript equivalent, and I tried below:
var url = "http://www.stackoverflow.com";
var xhr = new XMLHttpRequest();
xhr.open('GET', url, false);
xhr.send();
var response = xhr.responseText;
But it was blocked by CORS policy. Why Python works and JavaScript fails? Thanks.