Delphi:从网页获取正确的来源

mho*_*ude 2 html delphi user-agent web-scraping

我正在使用Delphi,我正试图从网页获取源代码.

我的问题是,当我使用Indy(idHttp)或Clever Components(clHttp)而不是IE和/或谷歌Chrome时,我会得到不同的源代码.

有没有什么方法可以用Delphi检索网页源,与浏览器显示的方式完全相同?

Mik*_*keD 8

这可能是因为控件发送的用户代理字符串与IE或Chrome使用的字符串不同.换句话说,SERVER发回的信息源不同于IE或Chrome.

例如,在TIdDHTTP中,设置:

Request.Accept=*/*
Request.CacheControl=no-cache
Request.Connection=Keep-Alive
Request.ContentType=application/x-www-form-urlencoded
Request.AcceptEncoding=gzip, deflate
Request.UserAgent=Mozilla/4.0 (compatible; MSIE 6.0; Win32)
Request.Host=(web site name)
Run Code Online (Sandbox Code Playgroud)