简体   繁体   English

我如何从其他网站 url php 或 jquery 的特定类中获取 img src

[英]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 .网站 A 中,我想从网站 B获取图像,该图像具有xyz 类 So how can I do that with PHP or JS or JQuery?那么我怎样才能用 PHP、JS 或 JQuery 做到这一点呢?

Website A is the place where I want the image.网站 A 是我想要图像的地方。

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.还可以设置标题以从任何其他 url 获取数据。希望这对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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