Форум по Delphi программированию

Delphi Sources



Вернуться   Форум по Delphi программированию > Все о Delphi > Интернет и сети
Ник
Пароль
Регистрация <<         Правила форума         >> FAQ Пользователи Календарь Поиск Сообщения за сегодня Все разделы прочитаны

Ответ
 
Опции темы Поиск в этой теме Опции просмотра
  #1  
Старый 16.09.2015, 09:43
Taemin Taemin вне форума
Прохожий
 
Регистрация: 07.02.2012
Сообщения: 45
Репутация: 10
По умолчанию Простенький парсер (нужна помощь)

Попытался написать простенький парсер html-кода страницы после удачной авторизации... что-то не удалось
Снифером HTTPAnalyzer посмотрел все GET и POST запросы, вроде бы делаю правильно, а результата нужного нет

Сайт
https://my.kyivstar.ua/
Логин
+380980561942
Пароль
435465

Код:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdHTTP, IdIOHandler, IdIOHandlerSocket, IdSSLOpenSSL, httpsend, ssl_openssl,
  OleCtrls, SHDocVw, synacode, synautil, Gauges, ExtCtrls, ComCtrls, Grids, DateUtils,
  sSkinManager;

type
  TForm1 = class(TForm)
    btn1: TButton;
    lbl1: TLabel;
    edt2: TEdit;
    mmo1: TMemo;
    mmo2: TMemo;
    lbl2: TLabel;
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


function FoundLocationStrNum(Headers: TStringlist): integer;
var
  FoundStrPos, i: integer;
begin
  Result := -1;
  for i := 0 to Headers.Count do
  begin
    FoundStrPos := Pos('Location: ', Headers.Strings[i]);
    if FoundStrPos > 0 then
    begin
      Result := i;
      exit;
    end;
  end;
end;

function GetHTTPStr(http: THTTPSend): string;
var
  BodyStream: TStringStream;
  BodyS: TStringList;
begin
  try
    BodyS := TStringList.Create;
    BodyStream := TStringStream.Create(result);
    begin
      BodyS.LoadFromStream(http.Document);
      result := BodyS.Text;
    end;
  finally
    BodyStream.Free;
    BodyS.Free;
  end;
  http.Document.Seek(0, soFromBeginning);
end;

procedure TForm1.btn1Click(Sender: TObject);
label
  ERRORLabel;
var
  stream: TStringStream;
  httpsend: THTTPSend;
  Res: boolean;
  n: integer;
  KSlink, TOKEN, NewURL: string;
  A0,A1,A2,A3:String;
  REZ,z2,QW,result,before,after:String;
  i,z1,w,t,l:Integer;
  Cnt: Integer;
  today : TDateTime;
  lol1,GONJO:string;
  lol2:Integer;
  znach:Extended;
  //
  myDate,Date1,myDateX : TDateTime;
  m1 : Integer;
begin
      httpsend:=THTTPSend.Create;
      httpsend.AddPortNumberToHost:= False;
      httpsend.HTTPMethod('get', 'https://my.kyivstar.ua/tbmb/login/perform.do');
      Application.ProcessMessages;
      mmo1.Lines.LoadFromStream(httpsend.Document);
      Application.ProcessMessages;
   //-S-- Первый POST запрос ---
   stream := TStringStream.Create('');
   stream.WriteString('action=isCaptchaNeeded&user=%2B380980561942');
   Application.ProcessMessages;
   httpsend.Clear;
   httpsend.MimeType := 'application/x-www-form-urlencoded';
   httpsend.Document.LoadFromStream(stream);
   Res := httpsend.HTTPMethod('post', 'https://my.kyivstar.ua/tbmb/checkUser');
   Application.ProcessMessages;
   //-E-- Первый POST запрос ---
   //-S-- Второй POST запрос ---
   stream := TStringStream.Create('');
   stream.WriteString('isSubmitted=true&USERNAME=&USER_NAME=&ORIG_URL=&isInetUser=null&buser=&bpath=&user=%2B380980561942&password=435465&captcha=&value%28jumpTo%29=&value%28jumpToUrl%29=&Submit=%D3%E2%B3%E9%F2%E8');
   Application.ProcessMessages;
   httpsend.Clear;
   httpsend.MimeType := 'application/x-www-form-urlencoded';
   httpsend.Document.LoadFromStream(stream);
   Res := httpsend.HTTPMethod('post', 'https://my.kyivstar.ua/tbmb/login/perform.do');
   Application.ProcessMessages;
   //-E-- Второй POST запрос ---
   result:=IntToStr(httpsend.ResultCode);

         if result = '302' then
      begin
        lbl2.Caption:='Good!';
        Application.ProcessMessages;
      end;

      if result <> '302' then
      begin
        lbl2.Caption:='Bad!';
      end;

          if Res then
      case httpsend.ResultCode of
        301, 302, 307:
          begin
            n := FoundLocationStrNum(httpsend.Headers);
            if (n >= 0) and (n <= httpsend.Headers.count) then
            begin
              NewURL := StringReplace(httpsend.Headers.Strings[n], 'Location: ', '', []);
              Application.ProcessMessages;
              httpsend.Clear;
              httpsend.HTTPMethod('GET', NewURL);
              Application.ProcessMessages;
              mmo2.Lines.Text := GetHTTPStr(httpsend);
              Application.ProcessMessages;
            end;
          end;
      end;
end;
end.
Ответить с цитированием
Ответ


Delphi Sources

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB-коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход


Часовой пояс GMT +3, время: 03:28.


 

Сайт

Форум

FAQ

RSS лента

Прочее

 

Copyright © Форум "Delphi Sources" by BrokenByte Software, 2004-2023

ВКонтакте   Facebook   Twitter