摘要: raw_headers = """ key1: value1 key2: value2 key3: "value1",value1 """ #初始化空字典用于存储解析后的键值对 header_dict = {} #strip将字符串两端的字符移除,split以\n为分隔符进行切割 for line 阅读全文
posted @ 2023-12-21 17:58 暮色听雨 阅读(50) 评论(0) 推荐(0)
摘要: 跨请求保持cookie import requests s = requests.Session() s.cookies.update({'cookies_are': 'cookie'}) r = s.get(url='http://httpbin.org/cookies') print(r.tex 阅读全文
posted @ 2023-12-21 16:01 暮色听雨 阅读(30) 评论(0) 推荐(0)
摘要: session对象能够跨http请求保持某些参数 import requests s = requests.Session() #设置cookies s.get("http://httpbin.org/cookies/set/sessioncookie/123456789") #发送请求,查看当前请 阅读全文
posted @ 2023-12-21 15:16 暮色听雨 阅读(50) 评论(0) 推荐(0)
摘要: HTTP参数分为四种: 请求头参数(head) 存放在请求头中发送给服务器的参数,服务器通过这些参数能够正确解析请求的body 路径参数(path) 请求的资源路径,https://cn.bing.com/search?q=xxxxx&efirst=0&ecount=50,其中/search就是资源 阅读全文
posted @ 2023-12-21 14:34 暮色听雨 阅读(76) 评论(0) 推荐(0)
摘要: 安装Requests pip install requests 发送请求 接口: https://api.github.com/events 获取接口信息 r = requests.get('https://api.github.com/events') 之后获取的信息都是从r对象来的 其他的请求类 阅读全文
posted @ 2023-12-20 11:45 暮色听雨 阅读(31) 评论(0) 推荐(0)
摘要: ###导包 ``` import yaml ``` ### element.yaml ``` login: safe: '#element' link: '#element' user: ['#element','user1','user2','user3'] password: ['#elemen 阅读全文
posted @ 2023-08-28 23:22 暮色听雨 阅读(86) 评论(0) 推荐(0)
摘要: ###强制等待 必须要等待设定时间结束才会执行下一步操作 ``` import time time.sleep(3) ``` ###隐式等待 * 只用声明一次 * 隐式等待会在设定的时间内等待元素出现,若出现则会执行下一步操作,若没有出现则会抛出异常-TimeoutException * 在整个We 阅读全文
posted @ 2023-08-24 18:27 暮色听雨 阅读(127) 评论(0) 推荐(0)
摘要: ###浏览器操作 ``` #浏览器实例化 driver = webdriver.Chrome() #窗口最大化 driver.maximize_window() #窗口最小化 driver.miximize_window() #浏览器长、宽设置,单位:像素 driver.set_window_siz 阅读全文
posted @ 2023-08-23 19:47 暮色听雨 阅读(40) 评论(0) 推荐(0)
摘要: ###UI自动化测试代码的执行顺序就是:加载驱动->访问链接->页面操作 ``` import time from selenium import webdriver from selenium.webdriver.common.by import By #加载驱动 driver = webdriv 阅读全文
posted @ 2023-08-22 23:49 暮色听雨 阅读(90) 评论(0) 推荐(0)
摘要: ###方法一:元素ID定位 ``` username = driver.find_element(By.ID,"username") ``` ###方法二:元素class定位 ``` login = driver.find_element(By.CLASS_NAME,"login") ``` ### 阅读全文
posted @ 2023-08-22 23:41 暮色听雨 阅读(220) 评论(0) 推荐(0)