随笔分类 -  Requests

摘要:在新公司,所负责的业务后台是登录接口需要token, 然后后面的接口需要cookie来调用 解析:需要进入登录页面,在js中找到所需的token,放到登录接口参数中调用, 然后用requests.sesson方式来调用后续的接口完成自动化 1、下载 HTMLSession, pip3 install 阅读全文
posted @ 2020-10-20 11:34 dearddu 阅读(501) 评论(0) 推荐(0)
摘要:判断场景: 1、content-type : multipart/form-data 2、表单webforms为下图所示: 3、接口文档 使用: pip install requests-toolbelt 或 pip install requests-toolbelt --index-url htt 阅读全文
posted @ 2020-03-18 23:55 dearddu 阅读(190) 评论(0) 推荐(0)
摘要:如何快速从html页面解析出我们想要的数据 爬虫基本入门方法 场景: 1、当接口返回接口为xml 2、想从页面上解析想要的数据文本 使用 pip3 install lxml import request from lxml import etree r = requests.post(url,dat 阅读全文
posted @ 2020-03-18 23:41 dearddu 阅读(1296) 评论(0) 推荐(0)
摘要:接口返回的为html,但是我们需要取其中的某些字段进行传递。 答 :可以使用 正则 进行读取 正则口诀:知道前后取中间,遇到字符加转义 例如,想取下图标红字段, import re import requests url = 'xxxxxxx' r = requests.get(url).text 阅读全文
posted @ 2020-03-11 19:38 dearddu 阅读(2095) 评论(0) 推荐(0)
摘要:一、Session 关联 跨请求:比如登录之后发帖,这个发帖是依赖先登录的(需要传登录cookie) http协议是无状态的,也就是每个请求都是独立的。 那么登录后的一系列动作,都需要用cookie来验证身份是否是登录状态。 为了高效的管理会话,保持会话,于是就有了session 代码演示: 阅读全文
posted @ 2020-03-11 16:51 dearddu 阅读(240) 评论(0) 推荐(0)
摘要:import json dict = { 'xx':''123 } a = json.dumps(dict) # 字典转json print(type(a)) # 为 str 此时数据中 单引号变为双引号,Tuple -> list , Ture -> ture , None -> null jso 阅读全文
posted @ 2020-03-11 13:09 dearddu 阅读(151) 评论(0) 推荐(0)
摘要:用requests需要分清何时用data与json请求: 看请求头部参数 Post请求参数一部分在url里 另外一部分在body里面 第一种:application/json: {“key1“:”value1”,“keyt2":“value2"} json= 第二种:application/x-ww 阅读全文
posted @ 2020-03-10 18:49 dearddu 阅读(217) 评论(0) 推荐(0)
摘要:官方文档:http://2.python-requests.org/zh_CN/latest/user/quickstart.html 安装 1. 首先有python环境 2. pip install requests / pip install requests == 2.18.4 pip uni 阅读全文
posted @ 2020-03-10 15:48 dearddu 阅读(153) 评论(0) 推荐(0)