Heim  >  Artikel  >  Backend-Entwicklung  >  PHP如何采集网页指定标签里面的数据

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

WBOY
WBOYOriginal
2016-06-23 13:59:441335Durchsuche

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

    可以用正则表达式来匹配

    火车头工具……

    火车头工具……

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

    用正则匹配吧

  • Stellungnahme:
    Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn