PHP采集URL地址的问题

xr1211 2008-06-23 09:06:18
<?php
$rong = file_get_contents("http://www.google.com/products?q=gillette+mach3");
preg_match_all("/Did you mean:<\/span>(.*?)Refine product results for/s",$rong,$out, PREG_SET_ORDER);
preg_match_all("/href=\"\/product_url?q=(.*?)%3F/s",$out,$url, PREG_SET_ORDER);
print $url[0][1]
?>

我知道preg_match_all不能这样用,我想得到http://www.google.com/products?q=gillette+mach3 “ Did you mean:<\/span>(.*?)Refine product results for/s”中间所有的URL地址,但是得不到,

有没有什么好的方法可以得到指定HTML区域的URL地址! 希望把例子能写出来, 谢谢了!
...全文
138 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
fxs_2008 2008-06-24
  • 打赏
  • 举报
回复
多数正则都差不多
呵呵,50以下的正则,特别是10分以下的正则,可以直接找iasky
fxs_2008 2008-06-24
  • 打赏
  • 举报
回复
多数正则都差不多
呵呵,50以下的正则,特别是10分以下的正则,可以直接找iasky
fxs_2008 2008-06-23
  • 打赏
  • 举报
回复

$rong = file_get_contents("http://www.google.com/products?q=gillette+mach3");
//echo $rong;
preg_match_all("|product_url\?q=(.*?)\"|is",$rong,$out,PREG_SET_ORDER);
echo "<pre>";
print_r($out);
echo "</pre>";


这样的题下次多加点分啊!呵呵
iasky 2008-06-23
  • 打赏
  • 举报
回复
这题也就值10分
xr1211 2008-06-23
  • 打赏
  • 举报
回复
请问代码怎么写!麻烦您给写一下吧
fxs_2008 2008-06-23
  • 打赏
  • 举报
回复
第一步,用字符串截取获得Did you mean: <\/span>(.*?)Refine product results for/s”中间内容
第二步,再用正则或其他办法取得url

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧