Home > Mobile >  How to fix blank line issue in Pandas with Selenium?
How to fix blank line issue in Pandas with Selenium?

Time:12-30

I'm extracting the links from a page and saving it in an excel spreadsheet.

I have a problem, with the code, it skips a line to save the next link, as shown in the image below.

enter image description here

grupos = driver.find_elements(By.CLASS_NAME, "_7hkg")
for elm in grupos:
        link = elm.get_attribute("href")
        #link = elm.get_attribute("href").replace("m.","")
        print(link)
        links.append(link) 
        data = {'URL': links} 
        df = pd.DataFrame(data)
        df.to_excel(r"C:\__Imagens e Planilhas Python\LinksGrupo.xlsx", engine='xlsxwriter')
        print(df)

CodePudding user response:

if it is a list just use double colons before store into the pandas dataframe

links=links[0::2]# get the odd number index element from the list

or for even number

links=links[1::2]
  • Related