Solved

Retrieve the page from google for a search string

Posted on 2007-11-19
8
129 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:
ciuly 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 16

Author Comment

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

Expert Comment

by:ciuly
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:ciuly
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

13 Experts available now in Live!

Get 1:1 Help Now