以下是您的要求的示例代碼。此代碼基於python,selenium和crome exe文件。
from selenium import webdriver
from lxml.html import tostring,fromstring
import time
import csv
myfile = open('demo_detail.csv', 'wb')
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
driver=webdriver.Chrome('./chromedriver.exe')
csv_heading=["","","BIB","NAME","CATEGORY","RANK","GENDER PLACE","CAT. PLACE","GUN TIME","SPLIT NAME","SPLIT DISTANCE","SPLIT TIME","PACE","DISTANCE","RACE TIME","OVERALL (/814)","GENDER (/431)","CATEGORY (/38)","TIME OF DAY"]
wr.writerow(csv_heading)
count=0
try:
url="https://www.sportstats.ca/display-results.xhtml?raceid=4886"
driver.get(url)
table_tr=driver.find_elements_by_xpath("//table[@class='results overview-result']/tbody/tr[@role='row']")
for tr in table_tr:
lst=[]
count=count+1
table_td=tr.find_elements_by_tag_name("td")
for td in table_td:
lst.append(td.text)
table_td[1].find_element_by_tag_name("div").click()
time.sleep(5)
table=driver.find_elements_by_xpath("//div[@class='ui-datatable ui-widget']")
for demo_tr in driver.find_elements_by_xpath("//tr[@class='ui-expanded-row-content ui-widget-content view-details']/td/div/div/table/tbody/tr"):
for demo_td in demo_tr.find_elements_by_tag_name("td"):
lst.append(demo_td.text)
wr.writerow(lst)
table_td[1].find_element_by_tag_name("div").click()
time.sleep(5)
print count
time.sleep(5)
driver.quit()
except Exception as e:
print e
driver.quit()
你試過了什麼,結果是什麼?正如你在學校所做的那樣,請展示你的工作。 :)這是在SO上獲得問題的過程中的一部分。這對你很有幫助,因爲它會迫使你調查自己的問題並思考問題。這也向讀者證明你做了功課,並做出了合理的嘗試來回答你自己的問題。第三,它可以幫助讀者找到和診斷問題,爲您提供更好的答案,減少浪費時間。 – JeffC
嘗試在Selenium中使用''$(「。ui-row-toggler.ui-icon.ui-icon-circle-triangle-e」)。click()''來獲得所有''+''按鈕的點擊。然後,您可以像過去一樣分析生成的頁面。 – kxxoling