栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python爬虫

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python爬虫

#爬虫
import requests
import re
import os
# 判断你的路径是否有这个文件
image = '表情包'
if not os.path.exists(image):
    print("成功创建文件")
    os.mkdir(image)
else:
    print("文件已创建")
# 头部信息
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0'
    }
response = requests.get('https://qq.yh31.com/zjbq/',headers=headers)
response.encoding = 'GBK'
response.encoding = 'utf-8'
# 获取前端源码
# print(response.text)
# 获取网页头部
print(response.request.headers)
# 获取状态码
print(response.status_code)
# 正侧表达式
t = ''
# 获取照片信息,返回response.text中所有与t相匹配的全部字串,返回形式为数组
result = re.findall(t, response.text)
for img in result:
    print(img)
    res = requests.get(img[0])
    print(res.status_code)
    #获取图片格式
    s = img[0].split('.')[-1]
    #img[1]是图片名字,s是图片格式, mode='wb'二进制
    with open(image + '/' + img[1] + '.' + s, mode='wb') as file:
        # 写进去文件
        file.write(res.content)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/994505.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号