• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

请教各位大神改版后的四六级总分怎么用正则表达式获取(旧版的我会获取)

php 搞代码 4年前 (2022-01-23) 13次浏览 已收录 0个评论
文章目录[隐藏]

这是四六级网站

<table border="0" align="center" cellpadding="0" cellspacing="6" class="cetTable">	<tr>		<th>姓名:</th>		<td>赵阳</td>	</tr>	<tr>		<th>学校:</th>		<td>长春中医药大学</td>	</tr>	<tr>		<th>考试类别:</th>		<td>英语四级</td>	</tr>	<tr>		<th>准考证号:</th>		<td>220090132112529</td>	</tr>	<tr>		<th>考试时间:</th>		<td>2013年12月</td>	</tr>	<tr>		<th valign="top">总分:</th>		<td valign="top" class="fontBold">        <span class="colorRed">					0		        </span>		        	<br /><span class="color666">听力:</span>							000			            <br /><span class="color666">阅读:</span>						000						            <br /><span class="color666">写作与翻译:</span>						000					</td>	</tr></table>

这是我的代码

$a = curl_exec($ch);			$match="#<td>(.*)</td>#";			//$match="#<span>(.*)</span>#";preg_match_all($match,$a,$b);$yourname= $b[1][0];$school= $b[1][1];$cet= $b[1][2];$c= $b[1][5];//分数$score=strip_tags($c);$score=str_replace(" ","",$score);  		return array('school'=>$school,'name'=>$yourname,'cet'=>$cet,'score'=>$score);

其他的都能获取到 就总分那里获取不到

回复讨论(解决方案)

$a =<<< TXT<table border="0" align="center" cellpadding="0" cellspacing="6" class="cetTable">    <tr>        <th>姓名:</th>        <td>赵阳</td>    </tr>    <tr>        <th>学校:</th>        <td>长春中医药大学</td>    </tr>    <tr>        <th>考试类别:</th>        <td>英语四级</td>    </tr>    <tr>        <th>准考证号:</th>        <td>220090132112529</td>    </tr>    <tr>        <th>考试时间:</th>        <td>2013年12月</td>    </tr>    <tr>        <th valign="top">总分:</th>        <td valign="top" class="fontBold">        <span class="colorRed">                     0                 </span>                     <br /><span class="color666">听力:</span>                             000    <div style="color:transparent">本&文来源gaodai^.ma#com搞#代!码网</div><strong>搞gaodaima代码</strong>                     <br /><span class="color666">阅读:</span>                         000                                      <br /><span class="color666">写作与翻译:</span>                         000                     </td>    </tr></table>TXT;$match="#(.*?)#is";preg_match_all($match,$a,$b);$b[1][11] = preg_replace('/\s/', '', strip_tags($b[1][11]));print_r($b[1]);

Array
(
[0] => 姓名:
[1] => 赵阳
[2] => 学校:
[3] => 长春中医药大学
[4] => 考试类别:
[5] => 英语四级
[6] => 准考证号:
[7] => 220090132112529
[8] => 考试时间:
[9] => 2013年12月
[10] => 总分:
[11] => 0听力:000阅读:000写作与翻译:000
)

$a =<<< TXT<table border="0" align="center" cellpadding="0" cellspacing="6" class="cetTable">    <tr>        <th>姓名:</th>        <td>赵阳</td>    </tr>    <tr>        <th>学校:</th>        <td>长春中医药大学</td>    </tr>    <tr>        <th>考试类别:</th>        <td>英语四级</td>    </tr>    <tr>        <th>准考证号:</th>        <td>220090132112529</td>    </tr>    <tr>        <th>考试时间:</th>        <td>2013年12月</td>    </tr>    <tr>        <th valign="top">总分:</th>        <td valign="top" class="fontBold">        <span class="colorRed">                     0                 </span>                     <br /><span class="color666">听力:</span>                             000                         <br /><span class="color666">阅读:</span>                         000                                      <br /><span class="color666">写作与翻译:</span>                         000                     </td>    </tr></table>TXT;$match="#(.*?)#is";preg_match_all($match,$a,$b);$b[1][11] = preg_replace('/\s/', '', strip_tags($b[1][11]));print_r($b[1]);

Array
(
[0] => 姓名:
[1] => 赵阳
[2] => 学校:
[3] => 长春中医药大学
[4] => 考试类别:
[5] => 英语四级
[6] => 准考证号:
[7] => 220090132112529
[8] => 考试时间:
[9] => 2013年12月
[10] => 总分:
[11] => 0听力:000阅读:000写作与翻译:000
)

但$a里的内容应该是变化的啊

内容是变化的,格式是固定的
否则就无所谓“采集”了

内容是变化的,格式是固定的
否则就无所谓“采集”了

现在有个问题最后一行?>报错
我把你这个
$match=”#<t[hd].*?\>(.*?)#is”;
转义了还是报错


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:请教各位大神改版后的四六级总分怎么用正则表达式获取(旧版的我会获取)

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址