简体   繁体   中英

How to load a html page in javascript

I am trying to load a website into JavaScript so I can scrape it. My question is how would i load the website into client side JavaScript? I have tried loading it into a iframe and a JavaScript object element.

You'd use AJAX. In most cases, though, the same-origin policy will trip you up - JavaScript on example.com can't access the source code of example.net because they're different domains.

If both sites are under your control, CORS can fix this . If you're trying to scrape something like Facebook, you'd have to proxy the requests with some sort of server-side language like PHP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM