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

php采集文章图片不显示怎么办

php 搞代码 4年前 (2022-01-04) 23次浏览 已收录 0个评论

php采集文章图片不显示的解决办法:1、根据关键字采集百度搜寻结果;2、把采集到的html,根据定义的域名做一次批量转换即可。

本文操作环境:windows7系统、PHP7.1版、DELL G3电脑

php采集文章图片不显示怎么办?

PHP CURL采集百度搜寻结果图片不显示问题的解决方法

1.根据关键字采集百度搜寻结果

根据关键字采集百度搜寻结果,可以使用curl实现,代码如下:

<p><?php<br />function doCurl($url, $data=array(), $header=array(), $timeout=30){<br />  $ch = curl_init();<br />  curl_setopt($ch, CURLOPT_URL, $url);<br />  curl_setopt($ch, CURLOPT_HTTPHEADER, $header);<br />  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br />  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);<br />  curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);<br />  $response = curl_exec($ch);<br />  if($error=curl_error($ch)){<br />    die($error);<br />  }<br />  curl_close($ch);<br />  return $response;<br />}<br />$wd = '仙剑奇侠传';<br />$url = 'http://www.baidu.com/s?wd='.urlencode($wd);<br />$data = array();<br />$header = array();<br />$response = doCurl($url, $data, $header, 5);<br />echo $response;<br />?><br /></p>

输出后发现有部分图片不能显示

2.采集后的图片不显示原因分析

直接在百度中搜寻,页面是可以显示图片的。使用firebug查看图片路径,发现采集的图片域名与在百度搜寻的图片域名不同。

采集返回的图片域名 t11.baidu.com

正常搜寻的图片域名 ss1.baidu.com

查看采集与正常搜寻的html,发现有个域名转换的js是不一样的

采集

<p>var list = {<br />    "graph.baidu.com": <strong style="color:transparent">来源gaodai#ma#com搞@@代~&码网</strong>"http://graph.baidu.com",<br />    "t1.baidu.com":"http://t1.baidu.com",<br />    "t2.baidu.com":"http://t2.baidu.com",<br />    "t3.baidu.com":"http://t3.baidu.com",<br />    "t10.baidu.com":"http://t10.baidu.com",<br />    "t11.baidu.com":"http://t11.baidu.com",<br />    "t12.baidu.com":"http://t12.baidu.com",<br />    "i7.baidu.com":"http://i7.baidu.com",<br />    "i8.baidu.com":"http://i8.baidu.com",<br />    "i9.baidu.com":"http://i9.baidu.com",<br />};<br /></p>

正常搜寻

<p>var list = {<br />    "graph.baidu.com": "https://sp0.baidu.com/-aYHfD0a2gU2pMbgoY3K",<br />    "t1.baidu.com":"https://ss0.baidu.com/6ON1bjeh1BF3odCf",<br />    "t2.baidu.com":"https://ss1.baidu.com/6OZ1bjeh1BF3odCf",<br />    "t3.baidu.com":"https://ss2.baidu.com/6OV1bjeh1BF3odCf",<br />    "t10.baidu.com":"https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq",<br />    "t11.baidu.com":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq",<br />    "t12.baidu.com":"https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq",<br />    "i7.baidu.com":"https://ss0.baidu.com/73F1bjeh1BF3odCf",<br />    "i8.baidu.com":"https://ss0.baidu.com/73x1bjeh1BF3odCf",<br />    "i9.baidu.com":"https://ss0.baidu.com/73t1bjeh1BF3odCf",<br />};<br /></p>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php采集文章图片不显示怎么办

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

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

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

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