Python3 【requests使用】
一.状态码

二.基本使用
"""
requests第三方库:
pip install requests
req参数:
cookie
cookies
json[json数据格式]
text[文本]
content[二进制]
status_code[请求状态码]
headers[请求头]
url[网址]
history[请求历史]
1.请求参数
requests.get(url,headers=headers,params=data)
"""
#导入模块
import requests
import re
#请求网址
url = ""
headers = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWeb\
Kit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36"
}
#请求和添加请求头
req = requests.get(url,headers=headers)
#匹配模式
pattern = re.compile(‘<div.*?"card".*?href="(.*?)".*?card-img-top lazyload.*?data-src="(.*?)".*?</a>‘,re.S)
if not req.status_code == requests.codes.ok:
exit()
else:
html = req.text
#获取匹配内容
content = re.findall(pattern,html)
print(content) 相关推荐
chuckchen 2020-10-31
Dreamhome 2020-10-09
xirongxudlut 2020-09-28
星辰大海的路上 2020-09-13
chaochao 2020-08-31
猪猪侠喜欢躲猫猫 2020-08-17
快递小可 2020-08-16
shengge0 2020-07-26
巩庆奎 2020-07-21
张文倩数据库学生 2020-07-19
xirongxudlut 2020-07-18
Ericbig 2020-07-18
kyelu 2020-07-09
liangzhouqu 2020-07-07
GuoSir 2020-06-28
chaigang 2020-06-27
pythonxuexi 2020-06-25