使用selenium python为Riot.js填写用户名 - 登录框

时间:2016-12-28 09:31:26

标签: python selenium riot.js

https://sso.toutiao.com/login/?next=/&service=https://mp.toutiao.com/sso_confirm/?redirect_url=/

我正在尝试访问上面的网站,并使用selenium和python自动填充用户名。

似乎登录框是在Riot.js中写的,我在html中找不到用户名元素,如何使用selenium自动填充用户名?

我对selenium和Riot.js很新。

任何帮助将不胜感激。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import pyperclip
import sys


chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
browser = webdriver.Chrome(chrome_options=chrome_options) 
browser.get("https://sso.toutiao.com/login/next=/&service=https://mp.toutiao.com/sso_confirm/?redirect_url=/")

mobile = browser.find_element_by_id("mobile")
code = browser.find_element_by_id("code")

mobile.send_keys("xxxxx")
code.send_keys("xxxx")

1 个答案:

答案 0 :(得分:0)

用户名输入似乎有CSS ID account和xpath //*[@id="account"]。这应该足以让selenium访问它:

username_input = browser.find_element_by_xpath('//*[@id="account"]')
username_input.send_keys('username')