如何使用Selenium Python找到HREF属性
我尝试了许多网络解决方案,但找不到如何找到HREF。
我的代码之一:
driver = webdriver.Chrome(executable_path='C:\chromedriver.exe')
driver.get(("https://cordis.europa.eu/search/fr?q=contenttype%3D%27project%27%20AND%20programme%2Fcode%3D%27H2020%27&p=1&num=100&srt=/project/contentUpdateDate:decreasing"))
time.sleep(20)
driver.execute_script("window.scrollTo(0,10000)")
elems = driver.find_elements(By.CSS_SELECTOR, ".c-card-search__title.ng-star-inserted [href]")
links = [elem.get_attribute('href') for elem in elems]
insepctor:
<a _ngcontent-vtw-c99="" class="c-card-search__title ng-star-inserted" href="/project/id/881603"> Graphene Flagship Core Project 3 </a>
I tried many of the web solution but I can't find how to find the HREF.
One of my code:
driver = webdriver.Chrome(executable_path='C:\chromedriver.exe')
driver.get(("https://cordis.europa.eu/search/fr?q=contenttype%3D%27project%27%20AND%20programme%2Fcode%3D%27H2020%27&p=1&num=100&srt=/project/contentUpdateDate:decreasing"))
time.sleep(20)
driver.execute_script("window.scrollTo(0,10000)")
elems = driver.find_elements(By.CSS_SELECTOR, ".c-card-search__title.ng-star-inserted [href]")
links = [elem.get_attribute('href') for elem in elems]
The insepctor:
<a _ngcontent-vtw-c99="" class="c-card-search__title ng-star-inserted" href="/project/id/881603"> Graphene Flagship Core Project 3 </a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
href
属性在以下&lt; a&gt;
nodes中。解决方案,
打印
href
属性的值的 您必须诱导 a> for vineibility_of_all_elements_located() https://stackoverflow.com/questions/48369043/48369043/official-locator-strategies-for-the-webdriver"> loc> loc> loc> loc> loc> loc> :使用 css_selector使用 >:
使用 xpath :
控制台输出:
注意:您必须添加以下导入:
The
href
attributes are within the following<a>
nodes.Solution
To print the values of the
href
attribute you have to induce WebDriverWait for visibility_of_all_elements_located() and you can use either of the following locator strategies:Using CSS_SELECTOR:
Using XPATH:
Console Output:
Note : You have to add the following imports :
我希望Thi Swill解决您的问题,还请让我让我是否对您不起作用。
I hope thi swill solve your question, also, please let me if this will not work for you.