我想從這個(gè)網(wǎng)站表中抓取數(shù)據(jù): https: //www.oddsportal.com/moving-margins/ 這是我使用的代碼:它返回嵌套列表,將它們作為 csv 文件中的行,但結(jié)果我get 不準(zhǔn)確,尤其是當(dāng)一場(chǎng)比賽有多個(gè) tr[@class="odd"] 時(shí)u = 'https://www.oddsportal.com/moving-margins/'driver = webdriver.Chrome(executable_path=r"C:\chromedriver.exe")driver.maximize_window()driver.get(u)#Use Explicit time wait for fast executionWebDriverWait(driver, 30).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#moving_margins_content_overall")))driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")table_data = driver.find_elements_by_xpath("//div[@id='moving_margins_content_overall']//tr[@class='odd' or @class='dark']")table =[]# Creating a list of lists, where each list consist all data in each row either with class dark or oddfor data in table_data: row = [] dark_row = data.find_elements_by_xpath((".//th//a")) for col in dark_row: row.append(col.text.replace("\n"," ")) odd_row = data.find_elements_by_xpath((".//following-sibling::tr[@class='odd']//td")) for col in odd_row: row.append(col.text.replace("\n", " ")) table.append(row)for t in table: print(t)問(wèn)題是:有些比賽有多個(gè) tr[@class="odd"],我無(wú)法將每場(chǎng)比賽與其特定的相關(guān)聯(lián)tr[@class="dark"]沒(méi)有類的 tr 中還有另一個(gè)數(shù)據(jù)始終位于 tr="odd" 之前(contain th[@class="first2"]),我們可以添加此數(shù)據(jù)嗎?我們可以添加博彩公司名稱(最后的數(shù)據(jù)tr="odd")?
添加回答
舉報(bào)
0/150
提交
取消