Solved

Retrieve the page from google for a search string

Posted on 2007-11-19
8
130 Views
Last Modified: 2010-04-05
Hi.

I'd like to insert a specific search word and then submit this query to google.
Then retrieve the number of the result for a specific web page.

For example :
Word : "Experts Delphi source code"
Result : The page "Experts-exchange.com" is in   -> Page 3 , result #37

Thanks in advance.
0
Comment
Question by:CodedK
  • 3
  • 3
  • 2
8 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 20313308
0
 
LVL 16

Author Comment

by:CodedK
ID: 20313690
Hi MerijnB.
How can this help ?
0
 
LVL 28

Accepted Solution

by:
2266180 earned 500 total points
ID: 20314100
function Google_Search( keywords: TStringList ): TStringList;
begin
  Result := nil;
end;

lol :)

even though the problem is simple, it's not that simple.

if the above function would have had some code, then you could have modified that code pretty strait forward.

without that, you can do soemthing like this:

i:=0;
p:=0;// this will be the page
repeat
  html:=get_html('http://www.google.com/search?q='+url_encode(search query)+'&hl=en&start='+inttostr(i*10)+'&sa=N');
  inc(i);
  if pos(the_site, html)>0 then
    p:=i;
until p>0;

and you have the page in p.
ugly, but it will work :)

get_html is your prffered way of getting the html. I preffer indy: idhttp1.get(url)
url_encode is again your preffered way of encoding a string for url, mine is again indy: TIdUri.urlencode(text); (yes, it's a class function)
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20314449
oops, there used to be something usefull in there...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Author Comment

by:CodedK
ID: 20322755
Bad ciuly ... Lol
Thanks :)
0
 
LVL 28

Expert Comment

by:2266180
ID: 20322975
>> Bad ciuly ... Lol
why? the solution, not clean or beatifull, I know, but certainly speed optimal, short and easy to understand.
consider that almost any other solution (even that of merijnb if there was code tehre) involved parsing, which would mean more oeprations. you can further optimize for string speed tehre but since it's a network connection involved it doesn't really matter since generally it won't be noticeable.
tehre was one time the option of using google api but as I heard some time ago they are not giving the needed google api key anymore whithout which you cannot access some or all of the google api.
not to mention that this way it works on any search engine :P
0
 
LVL 16

Author Comment

by:CodedK
ID: 20323352
No ciuly your solution is good, clean and.. pliable. (I think this is a good word)
I said it coz of this >> mine is again indy: TIdUri.urlencode(text); (yes, it's a class function)
And i dont mean bad...bad ... but bad like SouthPark ("Rainforest Shmainforest") :P
Thanks :)
0
 
LVL 28

Expert Comment

by:2266180
ID: 20323944
ha. now I see hom I'm talking to :D
sorry, but I almost never look at the question asker when answering :)
I'm usually pressed by time so all I do is look at the question titile in the filter result, if it looks fast-answerable, I open it and read the question fast and answer even faster.
I never got around to making that utility I talked about since I'm too busy so this makes my life harder here. maybe next year :D

PS: I don't watch SouthPark :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now