aardio群 625494397
废话不多说 直接开整!
竟然还有脸收费 服了
下载对应版本的浏览器驱动
目标网址
应用场景 Selenium库涉及到
安装selenium库
pip install selenium-i https://mirrors.aliyun.com/pypi/simple/
下载对应浏览器驱动
https://registry.npmmirror.com/binary.html?path=chromedriver/
找到浏览器对应版本
最后直接上代码
# coding=utf-8import requests
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import time, random
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.chrome.options import Options
import re
import json
# import redisfrom selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome('D:\chrome\chromedriver.exe')
time.sleep(random.uniform(1,3))
driver.get('https://192.168.1.1100/soubei/login?spm=1607398886722')
wait = WebDriverWait(driver,2)
cookies = cookies ={'value':'E7E4FF92255985420FD71FBC81BC37C6','name':'ketangpai_home_remember'}#特别注意这里一定要设置cookie,然后配合使用
driver.add_cookie(cookie_dict=cookies)
user_name ='admin'
user_password ='123456'
WebDriverWait(driver,60,1).until(EC.presence_of_element_located((By.XPATH,'//input[@id="user-name"]')))# driver.find_element_by_name('user-name').clear()
driver.find_element_by_xpath('//input[@id="user-name"]').send_keys(user_name)
time.sleep(random.uniform(0.3,1.2))
WebDriverWait(driver,60,1).until(EC.presence_of_element_located((By.XPATH,'//input[@id="password"]')))# driver.find_element_by_name('password').clear()
driver.find_element_by_xpath('//input[@id="password"]').send_keys(user_password)
time.sleep(random.uniform(0.3,1.2))# 提交
driver.find_element_by_xpath('//*[@id="login-submit"]').click()
time.sleep(1)
script ='''
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
'''
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument",{"source": script})
driver.get("https://192.168.1.100/soubei/card/card/subsystem?systime=1608013694315")
time.sleep(1)
driver.refresh()
dictCookies = driver.get_cookies()print(dictCookies)for ii in dictCookies:
cookie = ii['value']print(cookie)
cook = dictCookies[1]['value']print(cook)
time.sleep(3)
cookie ='JSESSIONID={}; ketangpai_home_remember=E7E4FF92255985420FD71FBC81BC37C6'.format(cook)print(cookie)
本文转载自: https://blog.csdn.net/weixin_37254196/article/details/131556296
版权归原作者 白叔King 所有, 如有侵权,请联系我们删除。
版权归原作者 白叔King 所有, 如有侵权,请联系我们删除。