文章采集api(php采集文章图片不显示的解决办法:1、根据关键字采集百度搜寻结果)

优采云 发布时间: 2021-10-22 21:10

  文章采集api(php采集文章图片不显示的解决办法:1、根据关键字采集百度搜寻结果)

  今天PHP爱好者为大家带来php采集文章图片不显示的解决方法:1、根据关键字采集百度搜索结果; 2、@ >将采集中的html根据定义的域名进行批量转换。希望能帮到你。

  

  本文运行环境:windows7系统,PHP7.版本1,DELL G3电脑

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

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

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

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

  <p style="line-height: 2em; text-indent: 2em; text-align: left;"><br style="text-indent: 2em; text-align: left;"/></p>

  输出后发现有些图片无法显示

  

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

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

  采集返回的图片域名

  

  用于普通搜索的图像域

  

  查看采集和正常搜索html,发现有域名转换js不一样

  采集

  <p style="line-height: 2em; text-indent: 2em; text-align: left;">var list = {<br style="text-indent: 2em; text-align: left;"/>    "graph.baidu.com": "http://graph.baidu.com",<br style="text-indent: 2em; text-align: left;"/>    "t1.baidu.com":"http://t1.baidu.com",<br style="text-indent: 2em; text-align: left;"/>    "t2.baidu.com":"http://t2.baidu.com",<br style="text-indent: 2em; text-align: left;"/>    "t3.baidu.com":"http://t3.baidu.com",<br style="text-indent: 2em; text-align: left;"/>    "t10.baidu.com":"http://t10.baidu.com",<br style="text-indent: 2em; text-align: left;"/>    "t11.baidu.com":"http://t11.baidu.com",<br style="text-indent: 2em; text-align: left;"/>    "t12.baidu.com":"http://t12.baidu.com",<br style="text-indent: 2em; text-align: left;"/>    "i7.baidu.com":"http://i7.baidu.com",<br style="text-indent: 2em; text-align: left;"/>    "i8.baidu.com":"http://i8.baidu.com",<br style="text-indent: 2em; text-align: left;"/>    "i9.baidu.com":"http://i9.baidu.com",<br style="text-indent: 2em; text-align: left;"/>};<br style="text-indent: 2em; text-align: left;"/></p>

  普通搜索

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

  因此,根据源地址、IP、header等参数可以断定,如果是采集,百度会返回不同的js。

  3.采集图片不显示后的解决方法

  根据定义的域名批量传输采集中的html。

  <p style="line-height: 2em; text-indent: 2em; text-align: left;"><br style="text-indent: 2em; text-align: left;"/></p>

  添加域名转换后,所有图片均可正常显示。

  

  以上是php采集文章的详细内容,图片没有说明怎么做。更多详情请关注其他相关php粉丝文章!

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线