想抓取其中的内容,这个内容是从 http://www.xe.com/ucc/convert.cgi?Amount=1&From=EUR&To=USD 获得的,
在网页源码的 198 和 196 这两行
<td align="right" class="rate" >1.00 EUR<!-- WARNING: Automated extraction of data is prohibited under the Terms of Use. --></td> 
<td align="center" class="rate_equal">=</td> 
<td align="left" class="rate" >1.36799 USD<!-- WARNING: Automated extraction of data is prohibited under the Terms of Use. --></td>
我写了个程序,怎么感觉抓捕出来呢<?
$url = "http://www.xe.com/ucc/convert.cgi?Amount=1&From=EUR&To=USD";
$fp = @fopen($url, "r") or die("超时");
$fcontents = file_get_contents($url); eregi("<td align=\"right\" class=\"rate\">(.*)<!-- ",$fcontents,$right);
print_r($out);
print_r($right);
?>

解决方案 »

  1.   

    preg_match('|<td align="right" class="rate" >(.*?)<!--|',$fcontents,$right);
    var_dump($right);
      

  2.   

    同时说一下 ereg这样的函数在php5.3之后就取消了!
    所以 最好使用preg_match等
      

  3.   


    preg_match('|<td align="left" class="rate" >(.*?)<!--|',$fcontents,$left);
    var_dump($left);
    这个 left 抓不出来?
      

  4.   


    $url = "http://www.xe.com/ucc/convert.cgi?Amount=1&From=EUR&To=USD";
    $fcontents = file_get_contents($url);preg_match('|<td align="right" class="rate" >(.*?)<!--|ims',$fcontents,$right);
    var_dump($right);preg_match('|<td align="left" class="rate" >(.*?)<!--|ims',$fcontents,$right);
    var_dump($right);
    没问题啊array(2) { [0]=> string(44) "1.00 EUR string(8) "1.00 EUR" } array(2) { [0]=> string(46) "1.37649 USD string(11) "1.37649 USD" } 
      

  5.   


    谢谢楼上,东西抓取出来了。还有个问题,我发现这个网站 http://www.gormb.com/ 和我抓取的地方一样,但是他在每次查询汇率的时候,url里面却没有参数什么的,而我每次都是将一些参数提交到我的页面,然后在查询,我想问一下,怎么才能向他的一样啊。
      

  6.   

    你可以分析一下这个页面 
    在查询的地方 使用的是iframe调用http://www.gormb.com/convert/sample2.php这个页面但是这个页面内 使用的fomr表单的get传输如果查询 会对应http://www.gormb.com/convert/sample2.php?Amount=1&From=BRL&To=AUD&submit=%3F%3F%3F%3F&Service=xe 这样的get方法你分析一下吧···