简体   繁体   English

如何在Delphi中获取网页的源代码?

[英]How can I fetch the source of a Web page in Delphi?

I'm fetching Web page source with IdHTTP Indy component, but after reading about a problem with it and some questions on this Web site, it seems that it's not always the best choice. 我正在使用IdHTTP Indy组件获取网页源代码,但在阅读了有关它的问题以及该网站上的一些问题后,似乎并不总是最佳选择。

What are your suggestions for fetching Web pages? 您对获取网页有什么建议?

Use Indy. 使用Indy。 Create a TIdHTTP object and call its Get method. 创建TIdHTTP对象并调用其Get方法。 It returns the Web page source as a string, or places it in a stream that you provide. 它将网页源作为字符串返回,或将其放在您提供的流中。

An alternative is calling the WinInet functions, which is doable but a lot of work. 另一种方法是调用WinInet函数,这是可行的但很多工作。 If you already use COM/ActiveX objects, you could consider using MSXML2's XmlHttpRequest or the WinInet component: see here for an example http://yoy.be/item.asp?i142 如果您已经使用了COM / ActiveX对象,可以考虑使用MSXML2的XmlHttpRequest或WinInet组件:请参阅此处查看示例http://yoy.be/item.asp?i142

Or if you want to show the web-page on screen, you could use the TWebBrowser component: http://yoy.be/item.asp?i598 或者,如果你想在屏幕上显示网页,你可以使用TWebBrowser组件: http://yoy.be/item.asp?i598

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

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