aardio群 625494397
废话不多说 直接开整!
竟然还有脸收费 服了
下载对应版本的浏览器驱动
目标网址
应用场景 Selenium库涉及到
安装selenium库
pip install selenium-i https://mirrors.aliyun.com/pypi/simple/
下载对应浏览器驱动
https://registry.npmmirror.com/binary.html?path=chromedriver/
找到浏览器对应版本文章来源:https://www.toymoban.com/news/detail-563026.html
最后直接上代码文章来源地址https://www.toymoban.com/news/detail-563026.html
# coding=utf-8
import 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 redis
from 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)
到了这里,关于免费 Selenium各大浏览器驱动【谷歌chrme、火狐Firefox、IE浏览器】的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!