Selenium模拟登陆百度贴吧

时间:2022-12-21 14:03:23

Selenium模拟登陆百度贴吧


from selenium import webdriver
from time import sleep
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities # dcap = dict(DesiredCapabilities.PHANTOMJS)
# dcap["phantomjs.page.settings.userAgent"] = (
# "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36"
# )
# driver = webdriver.PhantomJS(executable_path='E:/phantomjs-2.1.1-windows/phantomjs-2.1.1-windows/bin/phantomjs.exe',desired_capabilities=dcap) # options = webdriver.ChromeOptions()
# options.add_argument('lang=zh_CN.UTF-8')
# options.add_argument('user-agent="Mozilla/5.0 (iPod; U; CPU iPhone OS 2_1 like Mac OS X; ja-jp) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5F137 Safari/525.20"')
# driver = webdriver.Chrome(executable_path='D:\chromedriver_win32\chromedriver.exe',chrome_options=options)
driver = webdriver.Chrome(executable_path='D:\chromedriver_win32\chromedriver.exe') driver.get("https://tieba.baidu.com/index.html#") driver.find_element_by_xpath("//li[@class='u_login']/div/a").click()
sleep(2)
driver.find_element_by_class_name('login-username').click() username =driver.find_element_by_id('TANGRAM__PSP_4__userName')
username.send_keys("413650185@qq.com")
password = driver.find_element_by_id('TANGRAM__PSP_4__password')
password.send_keys('luozhiyun2')
driver.find_element_by_id('TANGRAM__PSP_4__submit').click() sleep(5) driver.find_element_by_css_selector("div#onekey_sign>a").click() driver.find_element_by_css_selector(".j_sign_btn.sign_btn.sign_btn_nonmember").click()
driver.get_screenshot_as_file("D:/日志/2.png")
driver.quit()