static void convertHTML2XML(Args _args)
{
WinInet wi = new WinInet();
TextBuffer tb = new TextBuffer();
XML xmlString;
str page;
str filename;
int handle;
int i;
str tmpHTml;
container con;
str tmpString;
int tillWhere;
boolean firstSearch = true;
int fields = 0;
void formXML(int _i, str _value)
{
switch(_i)
{
case 1, 2: break;
case 3: xmlString += ‘
case 4: xmlString += ‘
case 5: xmlString += ‘’+_value+’’;break;
case 6: xmlString += ‘
case 7: xmlString += ‘
}
if (_i == 7)
{
fields = 0;
}
}
;
xmlString += ‘
handle = wi.internetOpenUrl(‘http://finanzas.inicia.es/cotizaciones/tiposInteres.php?Sesion_BolsamaniaES=2h5opigq5iuhad7te24ip1jpq1′);
if (handle)
{
page = wi.internetReadFile(handle);
//info(page);
}
con = str2con(web::stripHTML(page,true,true),’\n’);
for (i = 1; i < conlen(con); i++) { tmpString = strltrim(strreplace(conpeek(con, i),’\t’,”)); if (firstSearch) { if (strstartswith(tmpString,’Fecha’)) { tillWhere = i; firstSearch = false; fields = 1; } } tmpString = strreplace(tmpString,’\t’,”); if (strstartsWith(tmpString,’Tipos de interés de los bancos centrales’)) break; if (fields) { if (tmpString) { if (!strstartswith(tmpString,’Fecha’)) { formXML(fields, tmpString); fields ++; } } } } tb.setText(xmlString + ‘
tb.toFile(‘E:\\ExchangeRates.xml’); // use xmldocument instead
wi.internetCloseHandle(handle);
}
Note that I had to hardcode the column names to convert the same to XML. Do write in your comments if you can suggest better alternatives.
Aucun commentaire:
Enregistrer un commentaire