Website scraping using jquery and ajax

前端 未结 6 1748
孤独总比滥情好
孤独总比滥情好 2020-12-24 09:46

I want to be able to manipulate the html of a given url. Something like html scraping. I know this can be done using curl or some scraping library.But i would like to know i

6条回答
  •  感情败类
    2020-12-24 10:10

    You cannot do Ajax request to another domain-name than the one your website is on, because of the Same Origin Policy ; which means you will not be quite able to do what you want... At least directly.

    A solution would be to :

    • have some kind of "proxy" on your own server,
    • send your Ajax request to that proxy,
    • which, in turn, will fetch the page on the other domain name ; and return it to your JS code as response to the Ajax request.

    This can be done in a couple of lines with almost any language (like PHP, using curl, for instance)... Or you might be able to use some functionnality of your webserver (see mod_proxy and mod_proxy_http, for instance, for Apache)

提交回复
热议问题