本文目錄一覽:
php怎麼獲取遠程頁面中的一個div的內容
獲取遠程頁面可以用file_get_contents()函數或者curl拓展,後者的效率會更好,但需要你修改一些配置。
查找html頁面中的內容或者用phpQuery或這個:
或者用php原生的:
或者用正則。
如何用PHP 取DIV標籤內容
如果你要和之間的所有源碼,用preg_match就可以,不用preg_match_all,如果你要裡面的所有的標籤中的內容,可以用preg_match_all//提取所有代碼$pattern=’/(.+?)/is’;preg_match($pattern,$string,$match);//$match[0]即為和之間的所有源碼echo$match[0];//然後再提取之間的內容$pattern=’/(.+?)/is’;preg_match_all($pattern,$match[0],$results);$new_arr=array_unique($results[0]);foreach($new_arras$kkk){echo$kkk;}
php怎麼獲取指定div中的內容
-__________- 不早說。。取td裡面的東西?
?php
$str = EOF
div id=”trendTable”
table id=”trend_table_1″ border=”0″ cellspacing=”0″ cellpadding=”0″tr class=”trw”
td時間範圍/td
td用戶關注度/td
td媒體關注度/td
/trtr class=”trl”td1周/tdtdspan class=”dn”-3%/tdtdspan class=”dn”-45%/td/trtr class=”trf”td1個月/tdtdspan class=”up”+10%/tdtdspan class=”dn”-22%/td/trtr class=”trl”td1季度/tdtdspan class=”up”+3%/tdtdspan class=”dn”-30%/td/tr/table /div
EOF;
preg_match_all(‘/td(.*?)\/td/’, $str, $output);
echo “pre”;
print_r($output);
?
php如何獲取一個網頁中,指定某個div塊的內容
simple_html_dom這個通過篩選CLASS是可以獲得的,但是速度較慢。建議自己通過正則表達式確定想要或取的div塊。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/189976.html