App to copy urls from Google search results..possible?

Brainstorming an idea to create a program that can copy the url's of sites in the Google results pages and put them into a csv file.....is something like this possible in C++? I can draw it out fine but what methods should i implement to get this thing rolling?

Any takers....thanks
Hello,

You should use sockets. If you use OS Windows, then I can help you:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <windows.h>
#include <iostream>
#include <fstream>

#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "mswsock.lib")

int main()
{
	WSADATA wsa;
	SOCKET hSocket;
	sockaddr_in address;
	char szSite[128] = "\0", szIP[16] = "\0";
//	-----------------------------------------------------------------
	std::cout << "Enter an IP of a site:\n> ";
	std::cin >> szIP;
	std::cout << "Enter the page:\n> ";
	std::cin >> szSite;
	system("cls");
//	-----------------------------------------------------------------
	address.sin_family	= AF_INET;
	address.sin_addr.s_addr	= inet_addr(szIP);
	address.sin_port	= htons(80);
//	-----------------------------------------------------------------
	WSAStartup(0x0202, &wsa);
	hSocket = socket(AF_INET, SOCK_STREAM, 6);
	
	if(connect(hSocket, (sockaddr*)&address, sizeof(address)) == SOCKET_ERROR)
	{
		// Error
		// std::cerr << "An error #1\n";
		closesocket(hSocket);
		WSACleanup();
		return -1;
	}
//	-----------------------------------------------------------------
	std::ofstream ofFile("C:\\cpp\\HtmlCodeOfTheSite.html");

	if(ofFile.good())
	{
		int nCnt = 0;
		char szSnd[2048] = "\0";
		strcpy(szSnd, "GET ");
		strcat(szSnd, szSite);
		strcat(szSnd, " HTTP/1.0\r\n\r\n");

		if(send(hSocket, szSnd, strlen(szSnd), NULL) == SOCKET_ERROR)
		{
			// Error
			// std::cerr << "An error #2\n";
			closesocket(hSocket);
			ofFile.close();
			WSACleanup();
			return -1;
		}

		do
		{
			if((nCnt = recv(hSocket, szSnd, sizeof(szSnd), NULL)) == SOCKET_ERROR)
			{
				// Error
				// std::cerr << "An error #3\n";
				closesocket(hSocket);
				ofFile.close();
				WSACleanup();
				return -1;
			}

			ofFile.write(szSnd, nCnt);
		} while(nCnt > NULL);

		ofFile.close();
	}

	closesocket(hSocket);
	WSACleanup();
	return 0;
}


Results:


And the programme created a HTML file with the HTML code of the page ( /search?hl=ru&... ):
		...

href="http://www.cplusplus.com/" class=l><em>cplusplus.com</em> - The C++ Resources Network</a></h3>
<span class="std nobr">&nbsp;<span class=gl>-</span> [ <a href="http://translate.google.co.uk/translate?hl=
ru&amp;sl=en&amp;u=http://www.cplusplus.com/&amp;ei=Zk8UTPiBCYr2OYTmwfYL&amp;sa=X&amp;oi=translate&amp;
ct=result&amp;resnum=1&amp;ved=0CB4Q7gEwAA&amp;prev=/search%3Fq%3Dcplusplus.com%26hl%3Dru%26ie%3DUTF-8" 
class=fl>Перевести эту страницу</a> ]</span><div class="s">Includes references, tutorials, and a forum section 
where users can share their problems and ideas.<br><span class=f><cite>www.<b>cplusplus.com</b>/</cite> - 
<span class=gl><a href="http://webcache.googleusercontent.com/search?q=cache:UZ4gTJAPYGUJ:www.cplusplus.com/
+cplusplus.com&amp;cd=1&amp;hl=ru&amp;ct=clnk&amp;gl=uk&amp;ie=UTF-8">Сохраненная&nbsp;копия</a> - <a href="/search
?hl=ru&amp;ie=UTF-8&amp;q=related:www.cplusplus.com/+cplusplus.com&amp;tbo=1&amp;sa=X&amp;ei=Zk8UTPiBCYr2OYTmw
fYL&amp;ved=0CBMQHzAA">Похожие</a></span></span><br><table class=slk style="border-

		...


And. If you have the HTML code, then you can find the url's :)
Last edited on
Topic archived. No new replies allowed.