我正在尝试使用Selenium抓取网页,以便可以自动为客户报告指标。我尝试使用by_xpath,by_css和by_id
这是我的代码
driver = webdriver.Chrome(executable_path='C:/Users/Dan/Documents/Weekly Pulse 3/chromedriver')
url = 'https://login.constantcontact.com/login/login.sdo?goto=https%3A%2F%2Fwww.constantcontact.com%2Fprocessing_login.jsp'
url2 = 'https://ui.constantcontact.com/rnavmap/distui/contacts'
driver.get(url)
#assert "Constant Contact" in driver.title
username = driver.find_element_by_id("luser")
username.send_keys(user)
password = driver.find_element_by_id("lpass")
password.send_keys(pwd)
#elem.send_keys(Keys.RETURN)
submit = driver.find_element_by_id('login-button')
submit.click()
time.sleep(10)
driver.get(url2)
time.sleep(10)
#newsletter_elements = driver.find_elements_by_xpath("//*[@id='current_filter']")
newsletter_elements = driver.find_elements_by_css_selector("html body.bridge div.container div.container div#container div#application.row div div#contacts_index div.row div#filter_block.span9 div#current_filter span.message")
#html body.bridge div.container div.container div#container div#application.row div div#contacts_index div.row div#filter_block.span9 div#current_filter span.message
#//*[@id="current_filter"]/span
"""
wait = wait(driver, 10)
WebElement_Category_Body = wait.until(ec.visibilityOfElementLocated(By.id("current_filter")))
newsletter_elements = driver.find_element_by_xpath("//span[@class='message']")
这是HTML
<span class="message">Active (21403)</span>
有人遇到这个问题吗?这不是页面无法加载的问题。它返回一个空列表。