大神,我用php中的正则获取小说的章节内容,为什么获取的是空的,我不知道哪里错了. 10
求大神帮忙看看,谢谢这是要匹配的://<li><ahref="/chapter/7733231.html"title="章节名:第一章承业帝其人
章节字...
求大神帮忙看看,谢谢
这是要匹配的://<li><a href="/chapter/7733231.html" title="章节名:第一章 承业帝其人 章节字数:3127 更新日期:2017-04-23">第一章 承业帝其人</a><li>
这是代码:
<?php
$url = "网站地址";
$url = file_get_contents($url);
preg_match_all("!<li><a href=\"(.*?).html\" title=\"(.*?)\">(.*?)</a></li>!",$url,$result);
var_dump($result); 展开
这是要匹配的://<li><a href="/chapter/7733231.html" title="章节名:第一章 承业帝其人 章节字数:3127 更新日期:2017-04-23">第一章 承业帝其人</a><li>
这是代码:
<?php
$url = "网站地址";
$url = file_get_contents($url);
preg_match_all("!<li><a href=\"(.*?).html\" title=\"(.*?)\">(.*?)</a></li>!",$url,$result);
var_dump($result); 展开
2个回答
展开全部
echo "\n\n抓取网页=======================================\n";
function getHTTPS($url) {
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt ( $ch, CURLOPT_HEADER, false );
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_REFERER, $url );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, TRUE );
$result = curl_exec ( $ch );
curl_close ( $ch );
return $result;
}
$result = getHTTPS ( "当前网址" );
if (preg_match_all ( "/<li>(?:(?!<\/li>)[\s\S])*<\/li>/i", $result, $m )) {
for($j = 0; $j < count ( $m [0] ); $j ++) {
echo $m [0] [$j] . "\n";
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
内容中有(")(')(换行符)等等,需要用array把这些替换成空
function myTrim($str){$search = array(" "," ","\n","\r","\t","<br/>"," ","<br>","'",'"');$replace = array("","","","","","","","","","");return str_replace($search, $replace, $str);}
调用:
$页面 = myTrim($页面);//去空格..
function myTrim($str){$search = array(" "," ","\n","\r","\t","<br/>"," ","<br>","'",'"');$replace = array("","","","","","","","","","");return str_replace($search, $replace, $str);}
调用:
$页面 = myTrim($页面);//去空格..
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询