Home > database >  Web Scraping with Python - Because when I use FOR IN it just returns a string
Web Scraping with Python - Because when I use FOR IN it just returns a string

Time:11-30

Because when I print the item "Vagas", they return all the strings I need, but when I print "on_click" it returns only one string. And from what I've seen, it returns only the last string, ignoring the others.

soup = BeautifulSoup(stringue, "html.parser")

Vagas = soup.find_all(title="Vaga disponível.")

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

print(on_click)

Return of "Vagas".

`<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"/>,`

Return of "on_click"

javascript:window.open('Cadastro.aspx?id_agenda=0&id_turno=29/11/2022 19:00:00;29/11/2022 20:00:00&data=29/11/2022&id_turno_exportador=198397&id_turno_agenda=61298&id_transportadora=23213&id_turno_transp=68291&id_Cliente=40300&codigo_terminal=40300&codigo_empresa=1&codigo_exportador=24978&codigo_transportador=23213&codigo_turno=20&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');

CodePudding user response:

Put the print statement inside the for loop:

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

CodePudding user response:

@AbiSaran

But when I use Pandas DataFrame it returns me just a string too.

df = pd.DataFrame(on_click)
df.to_csv('TESTE.csv')

  • Related