Failed to grab dates in a cutomized manner out of a tabular content

前端 未结 3 1254
醉酒成梦
醉酒成梦 2021-01-07 13:34

I\'ve written a script in python in combination with selenium to parse some dates available within a table in a webpage. The table is located under the header NPL Vict

3条回答
  •  北海茫月
    2021-01-07 14:16

    Try to use below code:

    def get_content(driver,url):
        driver.get(url)
        dates = len(wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,"#tournamentTable tr.center.nob-border"))))
        for d in range(dates):
            item = driver.find_elements_by_css_selector("#tournamentTable tr.center.nob-border")[d]
            try:
                idate = item.find_element_by_css_selector("th span[class^='datet']").text
            except Exception: idate = ""
            for time_td in item.find_elements_by_xpath(".//following::td[contains(@class, 'table-time') and not((preceding::tr[@class='center nob-border'])[%d])]" % (d + 2)):
                try:
                    itime = time_td.text
                except Exception: itime = ""
                print(f'{idate}--{itime}')
    

提交回复
热议问题