簡體   English   中英

使用Javascript通過URL獲取另一個網站的源代碼

[英]Use Javascript to get the source code of another website using a URL

如何使用JavaScript通過URL查看網站的html源代碼

這是您要查找的代碼:

$.ajax({
   url: 'http://www.somesite.com/',
   type: 'GET',
   success: function(res) {
      var data = $.parseHTML(res);  //<----try with $.parseHTML().
      // data you will get full html code from given url

      // this is how you can fetch any element from html that fetched from url
      $(data).find('div.content').each(function(){
          $('#here').append($(this).html());
     });

   }
 });

注意:這是假設該網站啟用了CORS,對於大多數網站而言,這通常並不常見。(正如Patrick Roberts所說。感謝這一點:))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM