最近写一个彩票代购网站来玩,基本的功能都实现了,现在想自动更新数据。所以需要采集别的网站的数据,但正则表达式实在是不好搞,一直下不了手。
我想采集“中国竞彩网”的数据,比如http://info.sporttery.com/basketball/mnl_list.php
下的竞彩篮球下的4种玩法的4项数据。
之前我用过java的一个开源把网页抓取,提供了操作类似DOM的方法来抓取,但是由于每天数据对映的id会变化,所以不行。
 所以,求教各位大侠。希望大家提供点思路也好、代码更佳好。

解决方案 »

  1.   

    就知道你要搞这套
    <?php
    $str = <<<EOF
    <tr><td class="txc first" id="n001">周二301</td>
    <td class="txc">美国女子篮球联盟</td>
    <td class="fblue txl" id="t001"><a href='http://info.sporttery.com/basketball/info/bk_match_info.php?m=35354' target='_blank'>亚特兰大梦想<strong> VS </strong>印第安纳狂热</a></td>
    <td class="txc">12-10-03 06:59</td>
    <td class="txc"><input type="checkbox" id="m001001" value="50464953" onclick="select_match('001001')"/>2.15</td><td class="txc"><input type="checkbox" id="m001002" value="49465248" onclick="select_match('001002')"/>1.40</td> <td class="txc"><input type="checkbox" id="all001" onclick="bao('001',2)"/></td>
    <td class="tdC" width="40"><a href="http://info.sporttery.com/basketball/info/bk_match_info.php?m=35354&s=bk" target="_blank"><img src="http://static.sporttery.com/sinaimg/main/blank/zjzl/news.png" border="0" /></a><a href="http://info.sporttery.com/basketball/mnl_odds.php?mid=35354" target="_blank"><img src="images/tong.png" border="0" /></a></td></tr>
    </tr><tr><td class="txc first" id="n002">周二302</td>
    <td class="txc">美国女子篮球联盟</td>
    <td class="fblue txl" id="t002"><a href='http://info.sporttery.com/basketball/info/bk_match_info.php?m=35355' target='_blank'>西雅图风暴<strong> VS </strong>明尼苏达天猫</a></td>
    <td class="txc">12-10-03 08:59</td>
    <td class="txc"><input type="checkbox" id="m002001" value="52465248" onclick="select_match('002001')"/>4.40</td><td class="txc"><input type="checkbox" id="m002002" value="49464853" onclick="select_match('002002')"/>1.05</td> <td class="txc"><input type="checkbox" id="all002" onclick="bao('002',2)"/></td>
    <td class="tdC" width="40"><a href="http://info.sporttery.com/basketball/info/bk_match_info.php?m=35355&s=bk" target="_blank"><img src="http://static.sporttery.com/sinaimg/main/blank/zjzl/news.png" border="0" /></a><a href="http://info.sporttery.com/basketball/mnl_odds.php?mid=35355" target="_blank"><img src="images/tong.png" border="0" /></a></td></tr>
    </tr>
    EOF
    ;
    preg_match_all('/<tr.*?id="[^"]*?">([^<]*).*?([^>]*)<strong> VS <\/strong>([^<]*).*?onclick[^>]*>([^<]*).*?onclick[^>]*>([^<]*)/msi', $str, $match, PREG_SET_ORDER);
    echo '<textarea cols="80" rows="40">';
    print_r($match);
      

  2.   


    Array
    (
        [0] => Array
            (
                [0] => <tr><td class="txc first" id="n001">周二301</td>
    <td class="txc">美国女子篮球联盟</td>
    <td class="fblue txl" id="t001"><a href='http://info.sporttery.com/basketball/info/bk_match_info.php?m=35354' target='_blank'>亚特兰大梦想<strong> VS </strong>印第安纳狂热</a></td>
    <td class="txc">12-10-03 06:59</td>
    <td class="txc"><input type="checkbox" id="m001001" value="50464953" onclick="select_match('001001')"/>2.15</td><td class="txc"><input type="checkbox" id="m001002" value="49465248" onclick="select_match('001002')"/>1.40
                [1] => 周二301
                [2] => 亚特兰大梦想
                [3] => 印第安纳狂热
                [4] => 2.15
                [5] => 1.40
            )    [1] => Array
            (
                [0] => <tr><td class="txc first" id="n002">周二302</td>
    <td class="txc">美国女子篮球联盟</td>
    <td class="fblue txl" id="t002"><a href='http://info.sporttery.com/basketball/info/bk_match_info.php?m=35355' target='_blank'>西雅图风暴<strong> VS </strong>明尼苏达天猫</a></td>
    <td class="txc">12-10-03 08:59</td>
    <td class="txc"><input type="checkbox" id="m002001" value="52465248" onclick="select_match('002001')"/>4.40</td><td class="txc"><input type="checkbox" id="m002002" value="49464853" onclick="select_match('002002')"/>1.05
                [1] => 周二302
                [2] => 西雅图风暴
                [3] => 明尼苏达天猫
                [4] => 4.40
                [5] => 1.05
            ))
      

  3.   

    胜分差也不过是改动改动而已
    正则不过是根据你的需要拼凑语法而已,不高深
    google 正则表达式 30分钟入门 的那个足够用了