阅读背景:

模拟百度进行图片搜索,有问题可以留言

来源:互联网 

摹拟百度进行图片搜索

import requests
import re
#剖析页面我们先在百度图片搜索里面随笔输入一个"背景图片"取得连接以下
#https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=index&fr=&hs=0&xthttps=111111&sf=1&fmq=&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word=背景图片
#word为我们查找的内容


# data = input("请输入你要搜索的内容")
# rp = requests.get(f"https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=index&fr=&hs=0&xthttps=111111&sf=1&fmq=&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word={data}")
# rp.encoding = rp.apparent_encoding
# print(rp.text)
#试了一下很显著内容是毛病的,主体很多内容没有


#这时候候我们加headers
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.90 Safari/537.36"
}
#User-Agent是对我们起源的进行假装

data = input("请输入你要搜索的内容")
rp = requests.get(f"https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=index&fr=&hs=0&xthttps=111111&sf=1&fmq=&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word={data}",headers=headers)
rp.encoding = rp.apparent_encoding
data = ""middleURL":"(.*?)","
# print(rp.text)
#对url查找我们必定不要看原网页上的,要看拜访要求下来的text,他可能会相比于本来网页会少了点前缀之类的,但是确定会有一部份内容一样,绝对能发明的.
url = re.findall(data,rp.text,re.S)
print(url)


#下一步对就是对爬取的url再进行拜访可以将文件保留至本地,具体可以参考博客
https://www.cnblogs.com/pythonywy/p/10856508.htmlimport requests
import re
#剖析页面我们先在百度图片



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: