|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import urllib.request
- import re
- def url_open(url):
- req = urllib.request.Request(url)
- req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0')
- req.add_header('Referer', 'https://tieba.baidu.com/p/5961757739')
- response = urllib.request.urlopen(req)
- html = response.read().decode('utf-8')
- print(html)
- return html
- def get_img(html):
- p = r'<img class="BDE_Image" src="([^"]+\.jpg)"'
- imglist = re.findall(p, html)
- for each in imglist:
- filename = each.split('/')[-1]
- urllib.request.urlretrieve(each,filename,None)
- if __name__ == '__main__':
- html = url_open('https://tbmsg.baidu.com/gmessage/get?mtype=1&_=1543322273495')
- get_img(html)
复制代码
上面是视频教材里用爬虫访问女神吧的代码,然鹅,并没能返回任何图片地址
审核元素时是有的啊,我尝试打印返回的页面内容却发现是这样的
好像是json结构吗?可是里面也没有图片地址啊?这个问题要怎么解决,请大大赐教
这个只是js在作妖,找到那段js看一下是怎么做的。改写成python就好啦
|
|