import requests
r=requests.get('http://www.lingzhilab.com/resources/getAllRes?page=1')
# u'文本内容' bytes 类型
print(r.content)
# 获取内容并设置编码
print(r.content.decode('utf-8'))
# 文本编码
print(r.apparent_encoding) # utf-8
# 响应状态码
print(r.status_code) # 200
# 文本内容
print(r.text)
# JSON解码器
print(r.json())
传递URL参数:
GET请求
import requests
key_dist={'page':1,'page':2}
# 原本url地址:http://www.lingzhilab.com/resources/getAllRes?page=1
r=requests.get('http://www.lingzhilab.com/resources/getAllRes',params=key_dist)
# url正确编码
print(r.url) # http://www.lingzhilab.com/resources/getAllRes?page=2
# u'文本内容'
print(r.text)
POST请求
import requests
import json
key_dist={'page':1,'page':2}
# 原本url地址:http://www.lingzhilab.com/resources/getAllRes?page=1
#r=requests.post('http://www.lingzhilab.com/resources/getAllRes',data=key_dist)
r=requests.post('http://www.lingzhilab.com/resources/getAllRes',data=json.dumps(key_dist)) # json参数
# url正确编码
print(r.url) # http://www.lingzhilab.com/resources/getAllRes
# u'文本内容'
print(r.text)
设置超时时间
秒数设置为0.001秒,会抛出异常,一般会把这个值设置为20秒
import requests
link="http://www.lingzhilab.com/resources/getAllRes?page=1"
# 原本url地址:http://www.lingzhilab.com/resources/getAllRes?page=1
r=requests.get(link,timeout=0.001)
定制请求头
import requests
headers={
'Host': 'www.lingzhilab.com',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36'
}
r=requests.get('http://www.lingzhilab.com/',headers=headers)
print(r.status_code) # 200
构造session
headers={
'session':'JSESSIONID',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36'
}
reqeusts底层是urllib库
文章浏览阅读380次。先来无事,开始总结自己最近学过做过的东西。想想,数据才是所有网络和编程的核心,包括人工智能。但是自己的数据处理能力,仅仅停留在excel基础,只用代码完成过64个表格的批量筛选和提取。后来阅读和搜索发现,Python里面处理数据,pandas和numpy才是王道。所以最近开始想办法学习这两个东西。怎么学?看代码,看书,太枯燥。买课又不想花钱。经过研究发现,pandas是可以处理类似excel结..._pandas对于excel来说什么时候好用
文章浏览阅读955次。周计划和学习总结
文章浏览阅读1.1k次,点赞15次,收藏20次。本文基于前期介绍的风速数据(文末附数据集),介绍一种多特征变量序列预测模型CEEMDAN + CNN-Transformer,以提高时间序列数据的预测性能。
文章浏览阅读206次。抽象类与接口一、抽象类1. 抽象类基本定义抽象类使用abstract class定义,并且其中的方法也可利用abstract定义若干个抽象方法,这样抽象类的子类必须再继承抽象类时强制全部覆写方法import java.util.Date;public class AbstractDemo { public static void main(String[] args) { ..._模仿本章练习,将其中的抽象类改为接口
文章浏览阅读2.9k次。cvlib中detect_common_objects图像识别下载资源失败的问题失败原因解决方案提示类似以下的信息Downloading yolov3-tiny.cfg from https://github.com/pjreddie/darknet/raw/master/cfg/yolov3-tiny.cfgCould not establish connection. Download failed失败原因D:\Program Files\Python39\Lib\site-packages_yolov3 tiny download
文章浏览阅读5.4k次,点赞4次,收藏13次。#include <stdio.h>#include <unistd.h>#include <termios.h> static struct termios initial_settings, new_settings;static int peek_character = -1;void init_keyboard(void);void clo..._linux/input.h 键盘编号
文章浏览阅读9.2k次。oracle expdp/impdp 数据泵导入导出# 创建directory,指定导入导出时的数据存储路径create directory dir_dp as 'd:/database/dir_dp';# 授权grant read,write on directory dir_dp to user_name;# 查看目录及权限select * from dba_directories;-_impdb schemas
文章浏览阅读1k次。实验过程中在运行“./bin/hdfs dfs -cat output/*”语句查看结果时发生以下报错:Exception in thread "main" java.lang.UnsupportedClassVersionError: MapReduce/WordCount has been compiled by a more recent version of the Java Runtime (class file version 60.0), this version of the Java _unsupportedclassversionerror: wordcount has been compiled by a more recent v
文章浏览阅读1.4w次。Fatal error: Cannot redeclare class 原因详细介绍_fatal error: cannot declare class wp_rest_navigation_fallback_controller, be
文章浏览阅读3.4k次。Java GeneralPath::cubicTo绘制平滑曲线_java swing画平滑曲线
文章浏览阅读579次。从DOM(文本对象模型来看)DOM将文档中的节点看作是一个个的对象,包括文档节点(document),元素节点(标签名),属性节点(不是元素节点的子节点)、文本节点,注释节点,上面谈到的每个节点都是一个对象,其中元素节点包括但不限于html、head、body,浏览器为我们创建了访问文档中的节点的入口,也就是document对象,其中document对象也是window对象的属性,document对象是包括html对象的我们所说的网页,一般由三种组成HTML(结构)、CSS(表现)、Js(形式,实现交_body、html、视口三合一
文章浏览阅读149次。摘要:据《科创板日报》7 月 4 日报道,有消息称,Meta 将重返中国,已经与多家中国科技公司进行了讨论,目前可能会和腾讯进行合作,后者或成为 Meta Quest 系列头显的独家经销商,且将为 Quest 头显开发 VR 游戏。对此,腾讯回应表示,不予置评。图片来源:由无界AI生成热点资讯腾讯将发布面向大模型训练的自研向量数据库据《科创板日报》7 月 4 日报道,腾讯云将在今日下午正式发布自研...