开发者

Open URL using Delphi

I'm doing a little (or at least I'm hoping it's开发者_开发百科 little) favor for a friend, but haven't used Delphi in 10 or so years... and my searches haven't been of much use

What I'm trying to do is to GET an URL and then parse the HTML to find some info he needs. I'm hoping for something like this (in python) fileHandle = urllib2.urlopen(urlStr) and fileHandle would receive the HTML of the page I requested. All examples I found opened the default browser, but

I'm using linux, with Lazarus and Free Pascal, he is using Delphi 7 (if I recall correctly) if that matters at all.

Thanks.


Using Indy you can use the TidHttp Component.

var
  http : TidHttp;
  page : String;
begin
  http := TidHttp.Create(nil);
  try
  page := http.get(URL);
  finally 
    http.Free;
  end;
end;

Get has several overloaded versions if you desired the contents in other formats and need to pass additional informaiton.


Options:

  1. Call wget (which you will have to install on Windows) to download the page to a text file and then open that.

  2. Use Indy or Synapse if you want to do it entirely in Delphi.

(I use Synapse to do this type of thing all the time).


Use a TWebbrowser in your app. You can get the value of textbox or click a button in the page.

var
  ovElements: OleVariant;
  i: Integer;
begin
  ovElements := WebBrowser1.OleObject.document.Forms.item(0).elements;
  for i := 0 to (ovElements.Length - 1) do
    if (ovElements.item(i).Name = 'ASPxButton1') 

      (ovElements.item(i).Name = 'ASPxButton1') then
      ovElements.item(i).Click;

OR

WebBrowser1.OleObject.document.Forms.item(0)
        .elements.item
        ('ASPTEXTBOXNAME').value;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜