1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| from selenium import webdriver from selenium.webdriver.chrome.options import Options import time
Url = "https://qzone.qq.com/" user_id = "防盗号字符串" password = "防盗号字符串"
options = Options()
options.add_argument("--disable-gpu") options.add_argument("--no-sandbox") driver = webdriver.Chrome(chrome_options=options)
driver.get(Url)
driver.switch_to_frame("login_frame")
driver.find_element_by_id("switcher_plogin").click() driver.find_element_by_id("u").clear() driver.find_element_by_id("u").send_keys(user_id) driver.find_element_by_id("p").clear() driver.find_element_by_id("p").send_keys(password)
time.sleep(3) try: driver.find_element_by_id("login_button").click() time.sleep(5) print("登陆成功") except: print("登录失败, 不要灰心, 生活中总是会遇到各种各样的问题")
try: print("开始点赞") InfoUrl = "https://user.qzone.qq.com/{}".format(user_id) driver.get(InfoUrl) print("切换到个人中心动态页面") btns = driver.find_elements_by_css_selector("i.fui-icon.icon-op-praise") print("CSS选择器开始运行") for btn in btns: btn.click() time.sleep(2) print("点赞成功") driver.quit() except: print("点赞中止, 不要灰心, 生活中总是会遇到各种各样的问题") driver.quit()
|