我正在尝试通过确实确实建立自己的Selenium能力。我之所以选择此网页,是因为它具有动态JS内容,而我不知道该如何使用其他Web抓取选项(例如请求和urllib)来工作。
确实有一个主页和一个微型的可滚动菜单,当单击到特定作业的链接时(在主页上),该菜单会显示在右侧。我可以成功使用link.click(),但是,无法在迷你页面中使用渲染的内容。 在进行故障排除时,我通过评论毫无头绪,但无法弄清楚我在做什么。.
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
chrome_options = Options()
#chrome_options.add_argument("--headless")
driverLoc = '/Users/jdmoore7/Downloads/chromedriver-2'
os.environ['webdriver.chrome.driver'] = driverLoc
driver = webdriver.Chrome(driverLoc, options=chrome_options)
driver.get('https://www.indeed.com/jobs?q=&l=Chicago,%20IL&advn=')
link = driver.find_element_by_id("sja0")
link.click()
# Everything works up to this point. Selenium cannot find the following tag...but I've visually verified that it exists.
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'vjs-desc')))
details = driver.find_element(By.ID, 'vjs-desc')
print(details)
最初,我认为这与iframe有关,但到目前为止,我还没有发现任何结论性
错误:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"vjs-desc"}
答案 0 :(得分:0)
您的ID {
auto p_i = new int{5};
auto up_i = std::unique_ptr<int>{p_i};
*p_i = 6; //nothing in the language prevent something like this
assert(*up_i == 6); //the unique_ptr ownership is not assured as you can see here
delete p_i; //still not illegal
} //at run time, RAII mechanism strikes, destroy unique_ptr, try to free an already freed memory, ending up to a core dumped
似乎没有什么意义,因为它看起来像是自动生成的。如果要单击链接,则应替换此行:
sja0
使用XPath Expression查找div element下的link = driver.find_element_by_id("sja0")
中class的链接,例如:
title
前进,您可以选择自己喜欢的链接或random one
links = driver.find_elements_by_xpath("//div[@class='title']/a")