from selenium import webdriver
import time
driver = webdriver.Firefox()
f = open("superliga.csv", "w")
driver.get("https://www.transfermarkt.com/")
f.write("Emri,Pozicioni,Mosha,Cmimi\\n")
f = open("superliga.csv", "a")
time.sleep(1)
for page in range(1,4,1):
driver.get("https://www.transfermarkt.com/kategoria-superiore/marktwerte/wettbewerb/ALB1")
elementet=driver.find_elements("xpath","/html/body/div[2]/main/div[2]/div[1]/div/div[3]/div/table/tbody/tr")
for element in elementet:
Emri =element.find_element("xpath", "./td[2]/table/tbody/tr[1]/td[2]/a").get_attribute("innerHTML")
Pozicioni =element.find_element("xpath", "./td[2]/table/tbody/tr[2]/td").get_attribute("innerHTML")
Mosha =element.find_element("xpath", "./td[4]").get_attribute("innerHTML")
Cmimi =element.find_element("xpath", "./td[6]/a").get_attribute("innerHTML")
f.write("{},{},{},{}\n".format(Emri, Pozicioni,Mosha,Cmimi))
f.close()
此代码显示第一页的球员4次,我需要所有的球员是在4页
1条答案
按热度按时间icnyk63a1#
尝试以下操作。我稍微修改了URL。