Home > Back-end >  Why didn't get to page source code
Why didn't get to page source code

Time:09-22


Web address: http://caipiao.163.com/award/cqssc/20160517.html


This web page is netease web site lottery page, format is utf-8, how to quickly source code to get it out?? thank you

CodePudding user response:

Pay attention to the user-agent, directly in indy HTTP component can be directly obtained,

CodePudding user response:

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * access web page source code * * * * * * * * * * * *
The function GetWebPage (const Url: string) : string;
Var
Idp: TIdHTTP;//USES IDHttp
The begin
Result:=';
Idps:=TIdHTTP. Create (Application);
Try
Idp. HandleRedirects:=True;
Idp. Request. UserAgent:='Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon. The.net CLR 1.1.4322) ';
Result:=Utf8ToAnsi (UTF8Decode (idp) Get (Url)));
The finally
FreeAndNil (idp);
end;
end;
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * access web page source code * * * * * * * * * * * *


Procedure TForm1. Button1Click (Sender: TObject);
The begin
Memo1. Text:=getwebpage (' http://caipiao.163.com/award/cqssc/20160517.html ');
end;


Why the code to run can't get the source code, after, what's the problem? Temporarily suspended, please, thank you ~ ~ ~

CodePudding user response:

USES IdCompressorZLibEx

 
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * access web page source code * * * * * * * * * * * *
The function GetWebPage (const Url: string) : string;
Var
Idp: TIdHTTP;//USES IDHttp
The begin
Result:=';
Idps:=TIdHTTP. Create (Application);
Try
Idp. HandleRedirects:=True;
Idp.Com pressor:=TIdCompressorZLibEx. Create (nil);
Idp. Request. UserAgent:='Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon. The.net CLR 1.1.4322) ';
Result:=Utf8ToAnsi (idp) Get (Url));
The finally
FreeAndNil (idp);
end;
end;
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * access web page source code * * * * * * * * * * * *

CodePudding user response:

The
reference 3 floor pathletboy response:
USES IdCompressorZLibEx

 
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * access web page source code * * * * * * * * * * * *
The function GetWebPage (const Url: string) : string;
Var
Idp: TIdHTTP;//USES IDHttp
The begin
Result:=';
Idps:=TIdHTTP. Create (Application);
Try
Idp. HandleRedirects:=True;
Idp.Com pressor:=TIdCompressorZLibEx. Create (nil);
Idp. Request. UserAgent:='Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon. The.net CLR 1.1.4322) ';
Result:=Utf8ToAnsi (idp) Get (Url));
The finally
FreeAndNil (idp);
end;
end;
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * access web page source code * * * * * * * * * * * *



Eldest brother, USES what kind of package is IdCompressorZLibEx ah,,, I download on the net a IdCompressorZLibEx pas, run after is always wrong,


That page above is the charset=utf-8 format,,,,, not GB2312 format after my code to run, only show a "? '

CodePudding user response:

reference 4 floor qq1590720 response:
Quote: reference pathletboy reply: 3/f

USES IdCompressorZLibEx

 
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * access web page source code * * * * * * * * * * * *
The function GetWebPage (const Url: string) : string;
Var
Idp: TIdHTTP;//USES IDHttp
The begin
Result:=';
Idps:=TIdHTTP. Create (Application);
Try
Idp. HandleRedirects:=True;
Idp.Com pressor:=TIdCompressorZLibEx. Create (nil);
Idp. Request. UserAgent:='Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon. The.net CLR 1.1.4322) ';
Result:=Utf8ToAnsi (idp) Get (Url));
The finally
FreeAndNil (idp);
end;
end;
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * access web page source code * * * * * * * * * * * *



Eldest brother, USES what kind of package is IdCompressorZLibEx ah,,, I download on the net a IdCompressorZLibEx pas, run after is always wrong,


That page above is the charset=utf-8 format,,,,, not GB2312 format after my code to run, only show a "? '


IdCompressorZLibEx indy 10 built-in ZLIB component, USES can be used directly,

CodePudding user response:

Use WebBrowser
USES: ActiveX;

The function WB_SaveHTMLCode (WebBrowser: TWebBrowser; Const FileName: TFileName) : Boolean;
Var
Ps: IPersistStreamInit;
Fs: TFileStream;
Sa: cost;
The begin
Ps:=WebBrowser. Document as IPersistStreamInit;
Fs:=TFileStream. Create (FileName, fmCreate);
Try
Sa:=TStreamAdapter. Create (fs, soReference) as cost;
Result:=Succeeded (ps. Save (sa, True));
The finally
Fs. Free;
end;
end;

The function WB_GetHTMLCode (WebBrowser: TWebBrowser; ACode: TStrings) : Boolean;

Var
Ps: IPersistStreamInit;

Ss: TStringStream;
Sa: cost;
S: a string;
The begin
Ps:=WebBrowser. Document as IPersistStreamInit;
S:=';
Ss:=TStringStream. Create (s);
Try
Sa:=TStreamAdapter. Create (ss, soReference) as cost;
Result:=Succeeded (ps. Save (sa, True));
If the Result then ACode. Add (ss. Datastring);
The finally
Ss. Free;
end;
end;

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related