简体   繁体   中英

get a html element from another website (XSS)

How can I get a html element from another website directly into my site (not using an iframe).

For Example:

A page on another website has the following code (and nothing else);

<p>example text</p>

how can I get this into my website to be able to edit it. I can't directly copy the code because I want the code on my site to change in conjunction to the other site.

As you seem to have PHP tag, so if using PHP, you can use file_get_contents() , like

$html = file_get_contents('url_of_site/page.html');

or with DOMDocument , like:

$doc = new DOMDocument();
$doc->loadHTMLFile('http://some_site.com/');    

$html = $doc->getElementsByTagName('p');
print_r($html);

Note:: Due to Same Origin Policy , you cant do it with just javascript. If you want to do it with Javascript you need to create a proxy kinda stuff, like have a test.php file in your own server, add code to fetch content from other site into test.php file, and call this test.php file using javascript ajax.

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