pandas Python -如何从这个结果创建dataFrame

bvuwiixz  于 2022-12-02  发布在  Python
关注(0)|答案(1)|浏览(123)

如何从打印结果创建DataFrame?

for teste2 in Vagas:
     on_click = teste2.get('onclick')
     print(on_click)

print(on_click)返回了下面的几个字符串,我想将它们插入到一个csv文件中。

<input id="ctl00_ctl00_Content_Content_rpt_turno_4_ctl01_imb_vaga_1" name="ctl00$ctl00$Content$Content$rpt_turno_4$ctl01$imb_vaga_1" onclick="javascript:window.open('Cadastro.aspx?id_agenda=0&amp;id_turno=29/11/2022 3:00:00;29/11/2022 4:00:00&amp;data=29/11/2022&amp;id_turno_exportador=198397&amp;id_turno_agenda=61298&amp;id_transportadora=23213&amp;id_turno_transp=68291&amp;id_Cliente=40300&amp;codigo_terminal=40300&amp;codigo_empresa=1&amp;codigo_exportador=24978&amp;codigo_transportador=23213&amp;codigo_turno=4&amp;turno_transp_vg=68291','_blank','height=850,width=1000,top=(screen.width)?(screen.width-1000)/2 : 0,left=(screen.height)?(screen.height-700)/2 : 0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no');" src="../App_Themes/SisLog/Images/add-document.gif" style="height:20px;border-width:0px;" title="Vaga disponível." type="image"/>, 

<input id="ctl00_ctl00_Content_Content_rpt_turno_6_ctl01_imb_vaga_1" name="ctl00$ctl00$Content$Content$rpt_turno_6$ctl01$imb_vaga_1" onclick="javascript:window.open('Cadastro.aspx?id_agenda=0&amp;id_turno=29/11/2022 5:00:00;29/11/2022 6:00:00&amp;data=29/11/2022&amp;id_turno_exportador=198397&amp;id_turno_agenda=61298&amp;id_transportadora=23213&amp;id_turno_transp=68291&amp;id_Cliente=40300&amp;codigo_terminal=40300&amp;codigo_empresa=1&amp;codigo_exportador=24978&amp;codigo_transportador=23213&amp;codigo_turno=6&amp;turno_transp_vg=68291','_blank','height=850,width=1000,top=(screen.width)?(screen.width-1000)/2 : 0,left=(screen.height)?(screen.height-700)/2 : 0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no');" src="../App_Themes/SisLog/Images/add-document.gif" style="height:20px;border-width:0px;" title="Vaga disponível." type="image"/>,`
bweufnob

bweufnob1#

您不需要 Dataframe

with open('test.csv', 'a') as f:
    for item in Vagas:
        on_click = teste2.get('onclick')
        f.write(on_click+'\n')

或使用 Dataframe :

temp=[]
for i in Vagas:
    on_click = teste2.get('onclick')
    temp.append(on_click)

df = pd.DataFrame(temp)
df.to_csv('test.csv', mode='a', header=False, index=False)

相关问题