Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 删除隐藏元素_Python_Html_Selenium - Fatal编程技术网

Python 删除隐藏元素

Python 删除隐藏元素,python,html,selenium,Python,Html,Selenium,我的问题有两个: 1我正在尝试使用下面的代码登录此,源代码为。可以使用我提供的凭据,该凭据将在28天后过期,但为之后查看此内容的用户创建一个试用帐户相对轻松 from selenium import webdriver driver_path = 'Path to my downloaded chromedriver.exe file' url_login = 'https://www.findacode.com/signin.html' username = 'jd@mailinator.co

我的问题有两个:

1我正在尝试使用下面的代码登录此,源代码为。可以使用我提供的凭据,该凭据将在28天后过期,但为之后查看此内容的用户创建一个试用帐户相对轻松

from selenium import webdriver
driver_path = 'Path to my downloaded chromedriver.exe file'
url_login = 'https://www.findacode.com/signin.html'
username = 'jd@mailinator.com'
password = 'm%$)-Y95*^.1Gin+'

options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome(executable_path=driver_path, chrome_options=options)

driver.get(url_login)
assert '_submit_check' in driver.page_source
driver.find_element_by_name('id').send_keys(username)
driver.find_element_by_name('password').send_keys(password)
driver.find_element_by_xpath("//input[@value='Sign In']").submit()
我收到所有3个元素的以下错误:

selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
我对html/css/javscript的命令没有那么强大,但我尝试过使用waits,但收到了一个超时。下一步,我将尝试该线程中的ActionChains,但我很想听听对此有更多了解的人如何继续

2最终,我想通过在循环中改变url最后5个字符的代码,从这个源代码中获取特定的代码历史数据。用户必须登录,因此我上面的第一个问题是,在浏览器中查看我要查看的信息的方法是展开淡紫色代码历史记录表。我要查找的特定信息是任何行的日期,其中“操作”列为“添加”,而“注释”列为“代码添加”:

Date       Action Notes 
2018-01-01 Added  First appearance in code
2017-02-01 Added  Code Added
我在这里的问题是,由于我认为表是隐藏的,需要通过单击来展开以公开我要查找的数据,我该如何继续

编辑 下面是代码、伪代码和注释来解释我的第二个问题

url_code = "https://www.findacode.com/code.php?set=CPT&c="
driver.get(url_code+'0001U') # i'm presuming that this will preserve the login session
driver.find_element_by_id('history').click() # i intend for this to expand the Code History section and expose the table shown earlier in the post but it's not doing that
check whether the phrase "Code Added" occurs in page source
if so, grab the date that is in the <td nowrap> tag that is 2 tags to the left

如果Selenium不可能,我可以在最后两行中使用BeautifulSoup,但我需要帮助理解为什么我没有看到我要刮取的数据

页面上有两个表单,分别输入@name=id、@name=password和Sign-in按钮。第一个是隐藏的。您需要使用@name=login处理表单:


要登录此网站,您需要引导WebDriverWait使所需元素可单击,并且您可以使用以下解决方案:

代码块:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

driver_path = 'Path to my downloaded chromedriver.exe file'
url_login = 'https://www.findacode.com/signin.html'
username = 'jd@mailinator.com'
password = 'm%$)-Y95*^.1Gin+'

options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument("start-maximized")
options.add_argument('disable-infobars')
driver=webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get(url_login)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//form[@name='login']//input[@name='id']"))).send_keys(username)
driver.find_element_by_xpath("//form[@name='login']//input[@name='password']").send_keys(password)
driver.find_element_by_xpath("//form[@name='login']//input[contains(@value,'Sign In')]").submit()
print("Logged In successfully")
控制台输出:

Logged In successfully

你能解释一下为什么OP需要诱导WebDriverWait,而它在没有WebDriverWait的情况下工作得很好吗?@Andersson他在他的每一篇帖子中都要求使用webdriver等等,我仍然不知道他为什么这样做!谢谢你指出这一点。在html上仍在加速。对我问题的第二部分有什么想法吗?第二部分没有代码,所以问题不太清楚。。。如果需要获取多个URL来更改页码,您可以定义counter=1并使用driver.get'https://www.findacode.com/code.php?set=CPT&c=000%sU“%counter in a loop+每次迭代时递增计数器1我将尝试在一段时间内为其添加一些代码,但我的挑战是如何获取表的内容?还有第三个问题吗?:最好为每个问题创建记录单,因为很难分析代码并搜索根本原因。这不是第三个问题,只是第二个问题,显然可能没有明确阐述。我只是想澄清,第二个问题更多的是获取数据,而不是循环代码。
Logged In successfully