简体   繁体   English

使用Delphi打开URL

[英]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 我正在为朋友做一点(或者至少我希望是这样),但是十年左右没有使用Delphi ...而且我的搜索没有多大用处

What I'm trying to do is to GET an URL and then parse the HTML to find some info he needs. 我想做的是获取一个URL,然后解析HTML以查找他需要的一些信息。 I'm hoping for something like this (in python) fileHandle = urllib2.urlopen(urlStr) and fileHandle would receive the HTML of the page I requested. 我希望这样的东西(在python中) fileHandle = urllib2.urlopen(urlStr)和fileHandle会收到我请求的页面的HTML。 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. 我正在将Linux与Lazarus和Free Pascal一起使用,如果有关系的话,他正在使用Delphi 7(如果我没记错的话)。

Thanks. 谢谢。

Using Indy you can use the TidHttp Component. 使用Indy,您可以使用TidHttp组件。

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. 如果您需要其他格式的内容并需要传递其他信息,则Get有多个重载版本。

Use a TWebbrowser in your app. 在您的应用程序中使用TWebbrowser。 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;

Options: 选项:

  1. Call wget (which you will have to install on Windows) to download the page to a text file and then open that. 调用wget(必须在Windows上安装),将页面下载到文本文件,然后打开它。

  2. Use Indy or Synapse if you want to do it entirely in Delphi. 如果要完全在Delphi中进行,请使用Indy或Synapse。

(I use Synapse to do this type of thing all the time). (我一直使用Synapse来执行此类操作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM