Search This Blog

Sunday, May 31, 2009

geturl, C++ code to retrieve the first link to SEP definition

This is a major part of a SEP definition download via batch. Use wget to download the webpage. Read page, ignores all text until it reaches "targetUrl[]", then reads the rest of the url and saves as file "sep".

#include
#include
using namespace std;

int main()
{
char c;
int i = 0;
char targetUrl[] = "http://definitions.symantec.com/defs/";
char url[100];
ifstream inStream("sep");

while (!inStream.eof())
{
inStream.get(c);
while ((i != 37) && (c == targetUrl[i]))
{
url[i] = c;
i++;
inStream.get(c);
}

if (i != 37) //url not found
{
url[0] = '\0';
i = 0;
}
else
{
while (c != '\"')
{
url[i++] = c;
inStream.get(c);
}
url[i] = '\0';
inStream.close();
ofstream outStream("sep");
outStream << url;
outStream.close();
return 0;
}
}
return 0;
}

No comments: