簡體   English   中英

查找並單擊元素... Python Selenium

[英]Find and click element by… Python Selenium

我正在嘗試單擊一個元素。 在檢查元素中,我可以看到:

<a href="/sondc.phtml"><b>S</b>ondeos por territorios</a>

這是我的代碼:

from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("http://www.ogimet.com/")

bsObj = BeautifulSoup(html.read());

#print(bsObj)

nameList = bsObj.findAll("a")

我不知道href是什么意思。 我不知道這是否是一個屬性。 你能幫助我嗎?

如果您想單擊 selenium 的“Sondeos por territorios”鏈接,就可以了。

from selenium import webdriver

#this path may be different on your cpu, you need to install a browser driver
driver_loc = r'C:\chromedriver_win32\chromedriver.exe' 
url = 'http://www.ogimet.com/'

driver = webdriver.Chrome(driver_loc) 
driver.get(url)

the_link = driver.find_element_by_xpath('/html/body/table/tbody/tr[2]/td[1]/div[19]/a')
the_link.click()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM