【问题标题】:How Can I load a specific DIV from an external webpage, into a specific DIV of my website?如何将外部网页中的特定 DIV 加载到我网站的特定 DIV 中?
【发布时间】:2011-11-17 07:18:55
【问题描述】:

我想将外部网页的特定 Div 加载到我自己网站的特定 Div(无 iframe)中。 例如: 我在自己的网站上有一个这样的 div:

<div id="weather-status"> Weather Status </div>

我也有这个网站:http://www.timeanddate.com/weather/ 我想从这个站点(http://www.timeanddate.com/weather/)加载一个表到我的 div(天气状态) 我该怎么做?

【问题讨论】:

  • table id 可能是这样的:weather @Arif
  • @Arif: table id 不是很重要
  • 但您只需要表格数据..对吗?
  • @Arif:不,我需要table 数据和设计。正是以特定tablediv 开头的网页位置。所以div 可能代替tabledivtable 元素可能有id 或没有。
  • 答案现在已编辑。如果可行,请采纳答案。

标签: html load external webpage


【解决方案1】:
<?php
   $url = "http://www.timeanddate.com/weather/";
   $page_all = file_get_contents($url); 

   preg_match('#<table class="border2 lpad wa">(.*)</table>#ms', $page_all, $div_array);


   echo "<pre>";
   print_r($div_array[0]);
   echo "</pre>";
?>

使用以下 CSS:

.wa {
    margin: 0 auto;
}

.border2 {
    background: none repeat scroll 0 0 #D7D6DC;
}

.lpad tr td {
    padding: 0.2em;
}

【讨论】:

  • @Meghdad Hadidi 你用的是哪个版本的php?
  • 我使用的是 php 5.3.8 并且运行良好
  • PHP Version 5.1.4我现在将在在线主机上测试此代码。
  • 酷!我的朋友做得很好,但在桌子之前,它会打印以下代码:Array ( [0] =&gt; Array ( [0] =&gt;
  • 您之前的解决方案效果很好,但我想为另一个网站这样做,那么我怎样才能为preg_match 编写一个真正的模式来提取我想要的内容?
猜你喜欢
  • 1970-01-01
  • 2013-09-11
  • 1970-01-01
  • 2022-11-04
  • 2013-07-26
  • 2011-12-30
  • 1970-01-01
  • 2013-08-11
  • 2017-10-03
相关资源
最近更新 更多