简体   繁体   中英

how i get img src from a particular class from other website url php or jquery

In website A I want to fetch an image from website B which has class xyz . So how can I do that with PHP or JS or JQuery?

Website A is the place where I want the image.

Website B:

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <p>wdsadbsabd sad sa djsa dkj sakj dsa d asd jksa dkj asd ksa dkj asdjk </p> <p> <img src="" id="abc" /> <img src="dsad.jpg" class="xyz" /> </p> </body> </html>

You can use like this

$.ajax({
        url:'http://www.yoursitelink.com/',
        type:'GET',
        success: function(data){
        var html = data;
        $("#img").attr('src');
      }
    });

also set the header to get the data from any other url.Hope this will help you.

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