// C++ search engine #include #include #include #include #include // only works in Visual C++ 2005 and earlier // see http://www.hackthissite.org/articles/read/1078 for ideas on using LibCurl instead #include using namespace std; set parseWord(string input); int main() { char web[] = "http://minich.com/education/psu/cplusplus/index.php"; cout << "input a web site to search: "; cin >> web; cin.ignore(100, '\n'); string input = ""; cout << "input a term to be searched for: "; getline(cin, input); CAtlHttpClient client; CAtlNavigateData navData; client.Navigate(web, &navData ); const byte *text = client.GetBody(); bool found = false; string word = ""; set hashTable; while (*text != NULL && !found) { word = ""; if (*text == '<') { while (*text != '>') { text++; } } else { while (*text != '<') { word += *text; text++; } cout << word << endl; text--; } hashTable = parseWord(word); if (hashTable.count(input) > 0) { cout << input << " was found on the web page" << endl; found = true; } hashTable.clear(); text++; } if (!found) { cout << input << " was not found on the web page" << endl; } system("pause"); return 0; }// end of main set parseWord(string input) { set hashTable; for (int i = 0; i < input.size(); i++) { for (int k = input.size() - 1; k >= 0; k--) { hashTable.insert(input.substr(i, k - i)); } } return hashTable; } /* Minich's cleaner original version #include #include #include using namespace std; int main() { CAtlHttpClient client; CAtlNavigateData navData; client.Navigate("http://www.minich.com", &navData ); const byte *text = client.GetBody(); string word = ""; string input = "Chess"; bool found = false; cout << "Enter a word that you'd like to find: "; cin >> input; while (*text != NULL && !found) { word = ""; while (*text != ' ') { word += *text; text++; } text++; //cout << word << endl; if (word == input) { cout << word << " was found on the web page" << endl; found = true; } } if (!found) { cout << word << " was not found on the web page" << endl; } return 0; } */