正式开始:技术相关

Python弄明白以下类库:

1、json:

JSON (JavaScript Object Notation) 是一种轻量级的数据交换格式。Python3 中可以使用 json 模块来对 JSON 数据进行编解码,它主要提供了四个方法: dumpsdumploadsload

json.dump()

json.dumps()

json.load()

json.loads()

2、requests

参考学习了:

[331]python之requests的基本使用_周小董的博客-CSDN博客_python requests

Python—requests模块详解 - 小L小 - 博客园

import requests
import json

# 打开一个网页,get,post,pull,delete,head,options
url = "https://www.baidu.com"
response = requests.get(url)

# 设置返回的类型编码,一般都是utf-8或gbk,否则中文会出现乱码,此处非必需
response.encoding = 'utf-8'

# 查看返回的代码,正常为:200,404是找不到网页
print(response.status_code)

# 查看返回的类型:<class 'requests.models.Response'>
print(type(response))

# 查看返回的类型编码
print(response.encoding)

# 查看内容:用于获取文本及源代码的数据(将数据转变为字符串)
print(response.text)
# 查看内容:用于获取图片及音视频等数据(将数据转变为二进制)
print(response.content)

#获得响应头内容
print(response.headers)
print(response.headers['content-type'])

# 将内容追加写入文件里
file = open('temp.txt', 'a+', encoding='utf-8')
file.write(response.text)
file.close()

# 下载一个图片
imgage_url = 'http://c.biancheng.net/uploads/allimg/191009/1-191009162420B7.gif'
response = requests.get(imgage_url)

if response.status_code == 200:
    imagefile = open('imageDemo.jpg', 'wb')
    imagefile.write(response.content)
    imagefile.close()
    print("下载图片成功!")
else:
    print("下载图片出错。")



# Requests 参数相关 两种方式,一种是URL直接用?action=quey&name=aaa方式
url = 'https://www.baidu.com'
paras = {'action': 'quey', 'name': 'aaa'}
response = requests.get(url, params=paras)
print(response.url)

3、base64

url = "https://www.cnblogs.com/songzhixue/"
bytes_url = url.encode("utf-8")
str_url = base64.b64encode(bytes_url)  # 被编码的参数必须是二进制数据
print(str_url)

b'aHR0cHM6Ly93d3cuY25ibG9ncy5jb20vc29uZ3poaXh1ZS8='


url = "https://www.cnblogs.com/songzhixue/"
bytes_url = url.encode("utf-8")
str_url = base64.b64encode(bytes_url)  # 被编码的参数必须是二进制数据
print(str_url)

b'aHR0cHM6Ly93d3cuY25ibG9ncy5jb20vc29uZ3poaXh1ZS8='

 理工男(作者)自己的公众号:

        一个理工男的成长之路,如果你是理工男,带你“不正经”;如果你想了解理工男,带你认识理工男,他们是生活百事通,他们的生活简约而不简单。

不正经的原则:合规合法,信息保真能看懂,字越少事越大,学到真东西享受真实惠,有兴趣加入我一起“不正经”。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值