Hello. I am writing a parser for issuing Gosha and I am faced with a certain problem. I need to get links to the site from the found page, i.e. send request:

http://www.google.com/search?q=+edit1.text 

And I get the html code page code code:

 Source:= IdHTTP1.Get('http://www.google.com/search?q='+edit1.text); 

Then I find all the links from the page with the following code Code:

 while Pos('href="', Source) <> 0 do begin Delete(Source, 1, Pos('href="', Source) + Length('href="') - 1); ListBox1.Items.Add(Copy(Source, 1, Pos('"', Source) - 1)); Application.ProcessMessages; end; 

All this devil-machine works, but I get links in the form of a redirect, but I would like it to be direct links. I saw in some prog such an execution, but I did not find the source code

    3 answers 3

    I noticed in your code one not so much an error, but rather a vulnerability in the line:

     while Pos('href="', Source) <> 0 do 

    More specifically,

     Pos('href="', Source) 

    And more precisely in this required substring:

     'href="' 

    I can tell you for sure that not all web developers use double quotes when concluding a website address in the "href" parameter. Someone concludes the address of the site in single, someone in double, so that it is better to look in the resulting HTML-code not 'href="' , but 'href=' . This will reduce your vulnerability. Well, but to eliminate this vulnerability completely, you need to convert the HTML-code received as a result of a GET request to lowercase, using the lowercase function. You understand, someone will write " HrEf ", someone " href " ...

    Well, and then look in the code from the site for the word " href= "

      Why not to be soared with the href search, not to load the result into TWebBrowser and already follow the links in the DOM-model?

        Firstly, this task is not so easily solved, Google changes its markup very often, so regular pars will not always work.

        Secondly, if you really need it, there is a paid api, convenient for the developer, to search.

        I recommend to get acquainted with it.