本帖最后由 suchocolate 于 2020-11-23 20:08 编辑 from selenium import webdriver
from time import sleep
from selenium.webdriver import ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as expected
from selenium.webdriver.support.wait import WebDriverWait
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
bro = webdriver.Chrome(executable_path='./chromedriver',options=option)
bro.get('xxxxx')
wait = WebDriverWait(bro, 10) # 浏览器显示等待
wait.until(expected.visibility_of_element_located((By.ID, 'TANGRAM__PSP_4__userName'))) # 当用户名可见,再继续
userName_tag = bro.find_element_by_id('TANGRAM__PSP_4__userName')
password_tag = bro.find_element_by_id('TANGRAM__PSP_4__password')
userName_tag.send_keys('abcd@163.com')
sleep(1)
password_tag.send_keys('12345678')
sleep(1)
另外,selenium不带cookie会提示手工滑动验证,这个有难度。如果从浏览器手工导入cookie,不如用requests导入cookie,操作更快,不推荐用selenium。 |