求大侠写个获取网页内容的句子

bupabupa166 2010-08-02 10:35:42
目标网址:http://s.taobao.com/search?q=mm
我想获取“你是不是想找:” 后面的8个词语,不带连接的,并在页面中输出

大侠们帮帮我啊,谢谢
...全文
133 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
number123456 2010-08-02
  • 打赏
  • 举报
回复
你是想得到淘宝的相关搜索提示吗?
如果是,那是有接口的,
Dleno 2010-08-02
  • 打赏
  • 举报
回复
这个不是可以吗??

$url = "http://s.taobao.com/search?q=mm";
$html = file_get_contents($url);

$html = preg_replace('/>(\s+)/','>',$html);
$html = preg_replace('/(\s+)</','<',$html);
$html = preg_replace('/(\s+)/',' ',$html);
$html = str_replace("\r\n",'',$html);
$html = str_replace("\t",'',$html);

preg_match_all('~<div[^>]*?class="related-search-outter"[^>]*?><dl[^>]*?class="related-search"[^>]*?><dt>你是不是想找:</dt>(<dd><a href="(.*?)">(.*?)</a></dd>)+</dl></div>~is',$html,$data);
preg_match_all('~<dd><a href="(.*?)">(.*?)</a></dd>~is',$data[0][0],$data1);
print_r($data1[1]);

bupabupa166 2010-08-02
  • 打赏
  • 举报
回复
继续求救,大大们,小弟跪求能单独输出不带连接的8个关键字元素,例如:
echo "$match[0]<br>";
echo "$match[1]<br>";
echo "$match[2]<br>";
echo "$match[3]<br>";
echo "$match[4]<br>";
echo "$match[5]<br>";
echo "$match[6]<br>";
echo "$match[7]<br>";
bupabupa166 2010-08-02
  • 打赏
  • 举报
回复
就是类似下面的
echo "$match[0]<br>";
echo "$match[1]<br>";
echo "$match[2]<br>";
echo "$match[3]<br>";
echo "$match[4]<br>";
echo "$match[5]<br>";
echo "$match[6]<br>";
echo "$match[7]<br>";
echo "$match[8]";
Dleno 2010-08-02
  • 打赏
  • 举报
回复

$url = "http://s.taobao.com/search?q=mm";
$html = file_get_contents($url);

$html = preg_replace('/>(\s+)/','>',$html);
$html = preg_replace('/(\s+)</','<',$html);
$html = preg_replace('/(\s+)/',' ',$html);
$html = str_replace("\r\n",'',$html);
$html = str_replace("\t",'',$html);

preg_match_all('~<div[^>]*?class="related-search-outter"[^>]*?><dl[^>]*?class="related-search"[^>]*?><dt>你是不是想找:</dt>(<dd><a href="(.*?)">(.*?)</a></dd>)+</dl></div>~is',$html,$data);
preg_match_all('~<dd><a href="(.*?)">(.*?)</a></dd>~is',$data[0][0],$data1);
print_r($data1);
bupabupa166 2010-08-02
  • 打赏
  • 举报
回复
amani11 谢谢
能不能改成可以单独输出8个元素的啊,单个输出词语。“你是不是想找:” 这个不输出
bupabupa166 2010-08-02
  • 打赏
  • 举报
回复
大大们,求求你们了
amani11 2010-08-02
  • 打赏
  • 举报
回复

$html = file_get_contents("http://s.taobao.com/search?q=mm");

preg_match_all('/<dl class="related-search">(.*?)<\/dl>/is', $html, $match);
echo strip_tags($match[1][0]);
bupabupa166 2010-08-02
  • 打赏
  • 举报
回复
主要就是正则不会写哦
CunningBoy 2010-08-02
  • 打赏
  • 举报
回复
file_get_contents加preg_match_all
自己对照正则规则,先尝试写一写。
bupabupa166 2010-08-02
  • 打赏
  • 举报
回复
鄙视
tabris17
caizhuguanguan 2010-08-02
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 tabris17 的回复:]
懒得要命+笨得要死
[/Quote]

同意
tabris17 2010-08-02
  • 打赏
  • 举报
回复
懒得要命+笨得要死

21,893

社区成员

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

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