在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Delphi 通过URL地址获取网页源码的方法 uses WinInet, Classes, Windows; function UrlGetStr(const URL: string; ShowHeaders: boolean = false): string; const Agent = 'Internet Explorer 6.0'; var hFile, HInet: HINTERNET; Buffer: array[0..32767] of Char; BufRead: Cardinal; BufSize: Cardinal; TempStream: TStringStream; dwIndex: dword; begin HInet := InternetOpen(PChar(Agent), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); if Assigned(HInet) then try hFile := InternetOpenUrl(HInet, PChar(URL), nil, 0, 0, 0); TempStream := TStringStream.Create(''); dwIndex := 0; BufSize := SizeOf(Buffer); HttpQueryInfo(hfile, HTTP_QUERY_RAW_HEADERS_CRLF, @Buffer, BufSize, dwIndex); if ShowHeaders then TempStream.Write(Buffer, BufSize); if Assigned(hFile) then try with TempStream do try while InternetReadFile(hFile, @Buffer, BufSize, BufRead) and (BufRead > 0) do Write(Buffer, BufRead); Result := DataString; finally Free; end; finally InternetCloseHandle(hFile); end; finally InternetCloseHandle(hinet); end; end;
创建时间:2020.11.23 更新时间 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论