php网站绑定域名,企业的互联网推广,做t恤网站 一件也可以做,网站开发于制作总结需求#xff1a;从表格取不同的手机号和密码登录#xff0c;获取不同用户的信息#xff0c;写入本地表格requests官网#xff1a;https://github.com/requests/requests1、安装Requests模块1、官网下载requests包2、解压#xff0c;命令行进入python目录#xff0c;运行安…需求从表格取不同的手机号和密码登录获取不同用户的信息写入本地表格requests官网https://github.com/requests/requests1、安装Requests模块1、官网下载requests包2、解压命令行进入python目录运行安装命令python setup.py install测试有没有安装成功,如果import没有报错就是安装成功$cd d:\python$pythonimport requests打开pycharm导入requests即可2、request基本使用get请求params {key1: value1, key2: value2}resp_get requests.get(url_get, paramsparams) 2. POST请求设置header、cookies、请求参数headers {Accept-Encoding:gzip,deflate, Accept-Language:zh-cn}params {key1: value1, key2: value2}cookies dict(Cookiesg0yk_6c66_think_languagezh-Hans-CN; ekdf_4878119fa7b06c8ee66940ccdf424170c2cc0e10)resp_post requests.post(url_post, headersheaders, dataparams, cookiescookies)获取响应信息r requests.get(url_get, paramsparams)r.text # 获取响应内容r.encoding # 根据http头部返回响应编码r.status_code # 获取响应状态码r.headers # 响应头返回的类型是字典形式,r.headers[Content-Type] # http头部大小写不敏感所以访问响应头字段的时候任意大小写都可以r.cookies # 获取cookie####4. 完成登录接口//用手机号和密码访问登录接口并返回data登陆失败则返回0def userLoginRequest(self,account,password):requrl http://xxx.cn/login.jsonheader {……}cookies {……}params {fields:access_toke}params[account] account #读取手机号params[password] password #读取密码r requests.post(requrl,header,cookies,params)if(str(r.status_code)200): # 请求通过的时候才提取dataresponse json.loads(r.text)print(response[data])if(response[data]):return response[data]return 0自动读取表格的手机号密码调用登录接口再提取用户身份id,写入本地表格coding:utf-8import xlrdopenPath uE:/Automation/appiumCase/xxx/sheet/user.xlssavePath uE:/Automation/appiumCase/xxx/sheet/user2.xlsexcel xlrd.open_workbook(openPath)sheet excel.sheets()[0] # 读取第一个sheet数据result [uid, phone, password, token]for i in range(1, 200): # 循环次数取决于表格的数据行数phone str(sheet.row_values(i)[1])password str(int(sheet.row_values(i)[2]))resJon Login().userLoginRequest(phone, password) # 调用登录接口if (resJon ! 0):result.append(resJon[uid]) # 提取uidelse:print(str(sheet.row_values(i)[1]) Login error!) # 否则提示登陆失败ExcelUtil().writeArrayToExcel(result, 3, savePath) # 手机号密码uid写入表格