22-09-2022, Saat: 01:33
Merhaba,
Aşağıdaki kodlarla "delphican.com" sorunsuz çalışıyor "amazon.com" HTTP/1.1 405 Method Not Allowed hatası alıyorum.
Hatayı araştırdığımda UserAgent ile ilgili yazılar okudum fakat sorunu bir türlü çözemedim.
Sonunu nasıl çözerim?
First chance exception at $75EC0B42. Exception class EIdHTTPProtocolException with message 'HTTP/1.1 405 Method Not Allowed'. Process Amazonlar.exe (8212)
Aşağıdaki kodlarla "delphican.com" sorunsuz çalışıyor "amazon.com" HTTP/1.1 405 Method Not Allowed hatası alıyorum.
Hatayı araştırdığımda UserAgent ile ilgili yazılar okudum fakat sorunu bir türlü çözemedim.
Sonunu nasıl çözerim?
First chance exception at $75EC0B42. Exception class EIdHTTPProtocolException with message 'HTTP/1.1 405 Method Not Allowed'. Process Amazonlar.exe (8212)
function TMainForm.AmazonSearch(Const Search: String): String;
var
IdHTTP: TIdHttp;
Request: TStringList;
begin
Request := TStringList.Create;
IdHTTP := TIdHttp.Create;
try
IdHTTP.AllowCookies := True;
IdHTTP.HandleRedirects := True;
IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
// IdHTTP.Request.UserAgent := 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0';
IdHTTP.Post('https://www.amazon.com/', Request);
Result := IdHTTP.Get('https://www.amazon.com/'); // https://www.amazon.com/s?k=car+parts
finally
IdHTTP.Free;
Request.Free;
end;
end;
procedure TMainForm.Button1Click(Sender: TObject);
var
I: Integer;
ResultHtml: String;
Line, Rows, Doc: OleVariant;
begin
TButton(Sender).BeginUpdate;
ResultHtml := AmazonSearch('s?k=car+parts');
Doc := coHTMLDocument.Create as IHTMLDocument2;
Doc.Write(ResultHtml);
Doc.Close;
try
Rows := Doc.Body.All.Tags('span'); // Spandan verileri almaya başlıyoruz
for I := 0 to Rows.Length - 1 do
begin
Line := Rows.Item(I);
if Line.className = 'welcome' then
begin
Memo1.Lines.Add(Rows.Item(I).InnerText)
end;
end;
finally
TButton(Sender).EndUpdate;
end;
end;

