0
我試圖確定哪些文本是粗體,哪些不是,但所有的屬性返回正常,我希望如果有人可以向我解釋爲什麼,作爲以及最好的解決方法或解決它。python使用硒,value_of_css_property在輸出和檢查
我的Python代碼:
from selenium import webdriver
urls = (
"http://www.espn.co.uk/rugby/match?gameId=290767&league=180659",
"http://www.espn.co.uk/rugby/match?gameId=290768&league=180659")
driver = webdriver.Chrome("c:/temp/chromedriver_win32/chromedriver.exe")
driver.set_window_size(681,768)
for url in urls:
driver.get(url)
ft = driver.find_element_by_class_name("game-time")
if (ft.text) == "FT":
#Opens player stats window
driver.find_element_by_xpath("""//*[@id="global-nav-tertiary"]/div/ul/li[6]""").click()
posts = driver.find_elements_by_xpath("""//*[@id="main-container"]/div/div/div[1]/article/div/div[1]/div/div/div/table/tbody[1]/tr/td""")
for post in posts:
print post.value_of_css_property('font-weight')
driver.find_element_by_xpath("""//*[@id="main-container"]/div/div/div[1]/article/header/div/button[2]/span[2]""").click()
posts = driver.find_elements_by_xpath("""//*[@id="main-container"]/div/div/div[1]/article/div/div[1]/div/div/div/table/tbody[1]/tr/td""")
for post in posts:
print post.value_of_css_property('font-weight')
else:
#skipping all games that haven't played yet
pass
#closing driver
driver.quit()
輸出: 正常
元素檢測:
<span class="name" style="font-weight:bold;" data-reactid=".88mmgctyio.2.0.0.0.$sq.1.0.0.0.0.0.2.$2.0.0.0.$name.0">Jonathan Davies, C </span>