How do I output data to a CSV file with headers?

邮差的信 提交于 2019-12-24 02:18:35

问题


I want to output this data to a csv file. Currently, it's not appending anything when getting to the css_selector the text is not being appended. I want to append it to a list, then in a dataframe and then to a csv file.

list1=[]
for i, j in df1.iterrows():
    name = j[1]
    id1 = j[2]
    sleep(3)
    BI_box = WebDriverWait(driver, 
    10).until(EC.presence_of_element_located((By.ID,'BI')))
    BI_box.send_keys(id1)

    Last_Name_box = WebDriverWait(driver, 
    10).until(EC.presence_of_element_located((By.ID,'last')))
    Last_Name_box.send_keys(name)

    Sea= WebDriverWait(driver, 
    10).until(EC.presence_of_element_located((By.ID,'srch')))
    Sea.click()
    try:
        elm_result = driver.find_element_by_css_selector("span.flex[ng- 
        bind='(lbecord.F)']").text
        list1.append(elm_result)
        print(elm_result)
        print(list1)
    except:
        pass
    try:
        elm_result4 = driver.find_element_by_css_selector("span.flex[ng- 
        bind^='(la.record.B_DT ']").text
        list1.append(elm_result4)
    except:
        pass

    try:
        elm_result12 = driver.find_element_by_css_selector("span[ng- 
        bind='row.RISK_IND']").text
        list1.append(elm_result12)
    except:
        pass
    sleep(2)
    clear_btn = driver.find_element_by_id('clr')
    clear_btn.click()
    sleep(2)
    print(list1)

How do I solve the problem?

来源:https://stackoverflow.com/questions/57368284/how-do-i-output-data-to-a-csv-file-with-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!