>  기사  >  백엔드 개발  >  PHP如何采集网页指定标签里面的数据

PHP如何采集网页指定标签里面的数据

WBOY
WBOY원래의
2016-06-23 13:59:441381검색

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

    可以用正则表达式来匹配

    火车头工具……

    火车头工具……

    火车头能实现这种效果????????

    用正则匹配吧

  • 성명:
    본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.