基于API的爬虫

  • 通俗讲解APIhttps://www.zhihu.com/question/21430743
  • 利用网页API爬取数据https://zhuanlan.zhihu.com/p/418869045
  • 爬虫与APIhttps://zhuanlan.zhihu.com/p/36260167
  • 爬虫系列总结https://zhuanlan.zhihu.com/p/35379237
  • 如何找到数据的API  https://blog.csdn.net/qq_37860930/article/details/88742361

 

  • 编码和解码问题

功能:python中decode()的方法也是一个字符串编码方面的方法,与之相对应的是encode()字符串方法,但是decode()负责的是将字符串以指定的解码格式解码字符串。

使用格式如下:

str.decode(encoding='UTF-8',errors='strict')

参数说明:

str:需要解码的字符串;

encoding:指定的解码编码。

errors:是用来设置不同错误的处理方案的,默认值是strict。

返回值:

python的decode()方法将会返回经过指定解码编码解码后的新字符串。

使用测试笔记:

>>> str="我爱学习"

>>> str2=str.encode("UTF-8") #使用encode编码

>>> str2

b'\xe6\x88\x91\xe7\x88\xb1\xe5\xad\xa6\xe4\xb9\xa0'

>>> str2.decode("UTF-8") #使用decode解码

'我爱学习'

 

json.load(s)与json.dump(s)

1、区别

json.load:表示读取文件,返回python对象

json.dump:表示写入文件,文件为json字符串格式,无返回

json.dumps:将python中的字典类型转换为字符串类型,返回json字符串

json.loads:将json字符串转换为字典类型,返回python对象

load和dump处理的主要是文件

loads和dumps处理的是字符串

 

 

 

 

posted @ 2022-03-27 20:44  肥余  阅读(199)  评论(0)    收藏  举报