代码如下,不知道问题出在哪儿,请求返回的数据一直是没登录的数据
def login_with_cookie(self, mobile: str):
print(self._driver.get_cookies())
select1 = self.find(By.ID, "thisIsSiteId")
Select(select1).select_by_index(1)
self.find(By.ID, "telphone").clear()
self.find(By.ID, "telphone").send_keys(mobile)
# 发送手机验证码
self.find(By.ID, "getCaptcha").click()
time.sleep(15)
# 手动输入验证码后点击登录
self.find(By.CSS_SELECTOR, ".submit").click()
time.sleep(5)
# 登录成功后获取cookies
dict_cookie = self._driver.get_cookies()
print(dict_cookie)
# 退出系统后使用cookie登录
self.find(By.CSS_SELECTOR, ".logout").click()
# 使用cookie登录
for cook in dict_cookie:
self._driver.add_cookie(cook)
time.sleep(10)
self._driver.refresh()
time.sleep(5)
# 登录成功后做一个接口请求以验证登录成功
r = requests.get(url="http://xxxxxxx.com")
print(r.text)
return r.text