织梦采集,一般用不到采集网址有端口的情况,少数有端口的网址就无法采集了。总结了下dede无法采集端口不为80的网址错误解决:
问题描述,当采集的网址后代端口时(为防止有推广嫌疑就把网址换成xxx了。):
测试采集网址:http://www.xxx.com:89/index.php/main/news/index.html?channel_id=104&page=1
获取的列表测试信息网址是不带端口的结果是不带端口的数组集合:
测试的列表网址: http://www.xxx.com:89/index.php/main/news/index.html?channel_id=104&page=1
05 |
[title] => 讲座回放|施奠东—西湖,世界风景园林的 |
11 |
[title] => 喜报|恭贺我院2019年度西湖杯荣获佳绩! |
17 |
[title] => 讲座预告|西湖——世界风景园林的杰出范 |
23 |
[title] => 讲座回放|胡理琛—西湖七十年流变忆胜 |
29 |
[title] => 讲座回放|彭嘉恒—“南师、禅及其在西方 |
35 |
[title] => 讲座预告|胡理琛—西湖七十年流变忆胜 |
|
这样显然得到的网址是错误的。根本无法访问,也就无法采集了。
经过一番查找,原来是dede 设置HTML的内容和来源网址 的函数问题,漏写端口判断了。
在include/dedehtml2.class.php
function SetSource 函数里大概79行加上红框里的内容:
再测试一下。ok 了,这样网址就可以正常打开,采集到了。
付上代码:
01 |
function SetSource(&$html, $url = '' , $linktype= '' ) |
04 |
$this->CAtt = new DedeAttribute2(); |
06 |
$this->SourceHtml = $html; |
07 |
$this->BaseUrl = $url; |
09 |
$urls = @parse_url($url); |
10 |
$port=$urls[ 'port' ]== '80' ? '' : ':' .$urls[ 'port' ];//lyy 为80时候可以省略,否则就加上 |
11 |
$this->HomeUrl = $urls[ 'host' ].$port; |
12 |
$this->BaseUrlPath = $this->HomeUrl.$urls[ 'path' ]; |
13 |
$this->BaseUrlPath = preg_replace( "/\/([^\/]*)\.(.*)$/" , "/" ,$this->BaseUrlPath); |
14 |
$this->BaseUrlPath = preg_replace( "/\/$/" , '' ,$this->BaseUrlPath); |
17 |
$this->GetLinkType = $linktype; |
|