【发布时间】:2018-08-22 15:40:25
【问题描述】:
我的问题有两个:
1) 我正在尝试使用下面的代码登录到这个page,来源是here。可以使用我提供的凭据,该凭据将在 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 的命令没有那么强,但我已经尝试按照 thread 使用等待并收到超时。打算接下来尝试该线程中的 ActionChains,但很想听听对此有更多了解的人如何继续。
2) 最终,我想通过在循环中改变代码(url 的最后 5 个字符)从这个 url(源 here)中刮取特定的代码历史数据。用户必须登录,因此我上面的第一个问题,在浏览器中查看我所追求的信息的方法是展开浅紫色的“代码历史”表。我要查找的具体信息是 Action 列为“添加”且注释列为“代码添加”的任何行的日期:
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,但我需要帮助理解为什么我没有看到我想要抓取的数据
【问题讨论】: