I am trying to extract URLs from Google search results. I use Indy IdHTTP to get HTML results from Google, and I use Achmad Z’s code for getting the link hrefs from the page. How can I get the real link target for each URL instead of the one that goes through Google’s redirector?
I tried that but I get an “Operand no applicable” error in this part of the code:
function ToUTF8Encode(str: string): string;
var
b: Byte;
begin
for b in BytesOf(UTF8Encode(str)) do
begin
Result := Format('%s%s%.2x', [Result, '%', b]);
end;
end;
I use Delphi 7 with Indy 9.00.10. Maybe indy update will help ?
In the previous post here I’ve tried to explain why you should use Google Search API, in this one I’ll try to provide you an example with a hope it will work in your Delphi 7.
You need to have the
SuperObject(JSON parser for Delphi), I’ve usedthis version(latest at this time). Then you need Indy; the best would be to upgrade to the latest version if possible. I’ve used the one shipped with Delphi 2009, but I think theTIdHTTP.Getmethod is so important that it must work fine also in your 9.00.10 version.Now you need a list box and a button on your form, the following piece of code and a bit of luck (for compatibility 🙂
The URL request building you can see for instance in the DxGoogleSearchApi.pas mentioned before but the best is to follow the
Google Web Search API reference. In DxGoogleSearchApi.pas you can take the inspiration e.g. how to fetch several pages.So take this as an inspiration