Re: [請益] curl抓取網頁的問題
※ 引述《shadowjohn (3WA問題解決專家)》之銘言:
: ※ 引述《gemini392 (銘)》之銘言:
: : 最近在用PHP寫一個可以抓取"樂透號碼"的程式
: : 這是要抓取的網頁
: : http://www.taiwanlottery.com.tw/result_all.aspx
: : 但我一直無法抓取到全部的號碼 /_\
: : 以下是我寫的code
: : <?php
: : $url = "http://www.taiwanlottery.com.tw/result_all.aspx";
: : $ch = curl_init();
: : curl_setopt($ch, CURLOPT_URL, $url);
: : curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
: : $content = curl_exec($ch);
: : curl_close($ch);
: : preg_match('/<td class=number>.*?([\d]+).+?<\/td>/',$content,$target);
: : preg_match('/<td class=number_special>(.+?)<\/td>/',$content,$result);
: : echo $target[0];
: : echo $result[0];
: : ?>
: : 懇請大家替我解惑一下
: : 是正規表示式寫得不好?
: : 還是code本身需要改些什麼?
: preg_match('/<td class=number>.*?([\d]+).+?<\/td>/',$content,$target);
: ^^ 改成 tr
: 你大概就看出是哪的問題了~
真是太酷了!!!!!
非常感謝您 :)
想再請問一下
我這樣寫好像只能抓取第一次parse到的字串
那如果原始檔裡面還有其他相同的字串
要怎麼一併抓取出來?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.156.76
→
08/16 16:34, , 1F
08/16 16:34, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章