Maison > Article > développement back-end > PHP如何采集网页指定标签里面的数据
PHP采集问题,如何采集源码中ul标签里的数据,并写入本地数据库:
对方网页某一段源码如下:
<ul class="priceTableRows"> <li class="cq"> <span class="w1"><a href="http://www.xxxx.cn/exchange-priceItem-290-1-0.html" title=" 鸡骨草" target="_blank"> 鸡骨草</a></span> <span class="w2"><a href="http://www.xxxx.cn/exchange-prices-290-1-29001.html?t=1" title=" 大叶全草 广西" target="_blank"> 大叶全草 广西</a></span> <span class="w9">亳州</span> <span class="w3">17.00</span> <span class="w4">平</span> <span class="w5"><em class="up">126.67%</em></span> <span class="w6"><em class="up">126.67%</em></span> <span class="w7"><em class="up">286.36%</em></span> <span class="w8"><a href="http://www.xxxx.cn/exchange-prices-290-1-29001.html?t=1" title=" 鸡骨草" target="_blank"><img src="http://img.zyctd.com/MarketCondition/icon_chart.gif" / alt="PHP如何采集网页指定标签里面的数据" ></a></span> </li> <li> <span class="w1"><a href="http://www.xxxx.cn/exchange-priceItem-290-1-0.html" title=" 鸡骨草" target="_blank"> 鸡骨草</a></span> <span class="w2"><a href="http://www.xxxx.cn/exchange-prices-290-1-29002.html?t=1" title=" 小叶全草 广西" target="_blank"> 小叶全草 广西</a></span> <span class="w9">亳州</span> <span class="w3"> 20.00 </span> <span class="w4">平</span> <span class="w5"><em class="up">122.22%</em></span> <span class="w6"><em class="up">122.22%</em></span> <span class="w7"><em class="up">198.51%</em></span> <span class="w8"><a href="http://www.xxxx.cn/exchange-prices-290-1-29002.html?t=1" title=" 鸡骨草" target="_blank"><img src="http://img.zyctd.com/MarketCondition/icon_chart.gif" / alt="PHP如何采集网页指定标签里面的数据" ></a></span> </li> <li class="cq"> <span class="w1"><a href="http://www.xxxx.cn/exchange-priceItem-290-1-0.html" title=" 鸡骨草" target="_blank"> 鸡骨草</a></span> <span class="w2"><a href="http://www.xxxx.cn/exchange-prices-290-1-29003.html?t=1" title=" 大叶光杆 广西" target="_blank"> 大叶光杆 广西</a></span> <span class="w9">亳州</span> <span class="w3">20.00</span> <span class="w4">平</span> <span class="w5"><em class="up">42.86%</em></span> <span class="w6"><em class="up">42.86%</em></span> <span class="w7"><em class="up">127.27%</em></span> <span class="w8"><a href="http://www.xxxx.cn/exchange-prices-290-1-29003.html?t=1" title=" 鸡骨草" target="_blank"><img src="http://img.zyctd.com/MarketCondition/icon_chart.gif" / alt="PHP如何采集网页指定标签里面的数据" ></a></span> </li> ..........</ul>
采集的话用file_get_contents()/curl 都可以实现,先采集过来再截取你想要的内容。
如何写采集代码可以看这里:http://www.jb51.net/tools/zhengze.html
可以用正则表达式来匹配
火车头工具……
火车头工具……
火车头能实现这种效果????????
用正则匹配吧