Entwickler-Ecke
Internet / Netzwerk - Link-URLs auslesen
Maxman - Mi 25.09.02 16:55
Titel: Link-URLs auslesen
Hallo an alle!
Auf einer Homepage kann man über bestimmte Links die aktuellen Nachrichten ansehen. Die URLs, dieser Links ändern sich natürlich jeden Tag. Ich möchte ein Programm schreiben, das alle Link-URLs ausliest. Kann mir da bitte jemand helfen?
Danke im voraus!
Maxman
GPF - Mi 25.09.02 17:15
Ein ähnliches Problem mußte ich neulich auch lösen und bin da auf 2 Komponenten gestoßen:
Auf
http://www.euromind.com/iedelphi/ findest Du den
IEParser (unter dem Punkt UI-Less Parser). Die Komponente übernimmt den Ladevorgang und zerstückelt sämtliche Webseiten sehr detailiert. Der einzigste Haken dabei ist aber, daß hier anscheinend die MS Internetroutinen verwendet werden - scheinbar werden einige Scripte und ActiveX Routinen mit ausgeführt. Nähergehend beschäftigt habe ich mich hiermit nicht.
Die andere Komponente namens
HTML Parser kannst Du hier saugen:
http://www.jazarsoft.com/vcl/. Hier werden die Scripte nicht ganz so umfangreich geparst - allerdings mußt Du die Webseiten manuell erst einmal über Indy, ICS, WinINet, etc manuell herunterladen. Für meine Zwecke reichte dies aber vollkommen aus.
DeCodeGuru - Mi 25.09.02 17:18
du kannst die HTML-Datei mit URLDownloadToFile runterladen, diese dann in einer Stringlist öffnen und dann alle Links raussuchen. Zur Funktion URLDownloadToFile habe ich hier mal einen Auszug aus der PSDK:
Zitat: |
Downloads bits from the Internet and saves them to a file.
Syntax
Quelltext 1: 2: 3: 4: 5: 6:
| HRESULT URLDownloadToFile( LPUNKNOWN pCaller, LPCTSTR szURL, LPCTSTR szFileName, DWORD dwReserved, LPBINDSTATUSCALLBACK lpfnCB ); |
Parameters
pCaller
Pointer to the controlling IUnknown interface of the calling Microsoft® ActiveX® component (if the caller is an ActiveX component). If the calling application is not an ActiveX component, this value can be set to NULL. Otherwise, the caller is a Component Object Model (COM) object that is contained in another component (such as an ActiveX control within the context of an HTML page). This parameter represents the outermost IUnknown of the calling component. The function attempts the download within the context of the ActiveX client framework and allows the caller's container to receive callbacks on the progress of the download.
szURL
Pointer to a string value containing the URL to be downloaded. Cannot be set to NULL.
szFileName
Pointer to a string value containing the name of the file to create for bits that come from the download.
dwReserved
Reserved. Must be set to 0.
lpfnCB
Pointer to the caller's IBindStatusCallback interface. URLDownloadToFile calls this interface's IBindStatusCallback::OnProgress method on a connection activity, including the arrival of data. IBindStatusCallback::OnDataAvailable is never called. Implementing IBindStatusCallback::OnProgress allows a caller to implement a user interface or other progress monitoring functionality. It also allows the download operation to be canceled by returning E_ABORT from the IBindStatusCallback::OnProgress call. This can be set to NULL.
Return Value
Returns one of the following values.
E_OUTOFMEMORY The buffer length is invalid or there was insufficient memory to complete the operation.
S_OK The operation succeeded.
|
Dann hätte ich mal nen Code, mit dem du alle Links aus einer HTML-Datei raussuchen kannst. Der Code ist jedoch alt, funktioniert aber. Achja, den Code musst du natürlich noch anpassen. :mrgreen:
Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73:
| procedure TMainForm.LoadInformation; var i,k,l,oldpos: Integer; tmp, url, test: String; fertig,ende: Boolean; tmpfile,temp: TStringlist; begin temp := TStringList.Create; tmpfile := TStringlist.Create; try tmpfile.LoadFromFile(DirPath+'tmp.thm'); tmp := tmpfile.Text; oldpos := 1; for i := 1 to Length(tmp) do begin k := Pos('href=',Lowercase(tmp)); if k = 0 then begin break; end else begin Delete(tmp,1,k); temp.Add(IntToStr(oldpos + k - 1)); oldpos := oldpos +k; end; end;
{*}Debug.Add(TimeToStr(Now)+'/'+DateToStr(Now)+': '+'Links wurden lokalisiert'); {*}Debug.SaveToFile(debugpath);
Application.ProcessMessages;
//Jetzt werden die Links rausgesucht
for i := 0 to temp.Count -1 do begin url := ''; fertig := false; ende := false; k := StrToInt(temp[i]); for l := k + 6 to Length(tmpfile.Text) do begin test := Copy(tmpfile.Text,l,1); if (test <> '"') and (fertig = false) and (ende = false) then begin url := url + test; end; if (test = '"') and (fertig = false) and (ende = false) then begin fertig := True; ende := True; end; if (fertig = True) and (ende = True) then begin with ListView.Items.Add do begin Caption := ExtrFileName(url); SubItems.Add(CorrectURL(url)); end; break; {*}Debug.Add(TimeToStr(Now)+'/'+DateToStr(Now)+': '+'Übersicht wurde um gefundene Dateien erweitert'); {*}Debug.SaveToFile(debugpath); end; end; end; finally temp.Free; tmpfile.Free; InfLoaded := True; Application.ProcessMessages; end; end; |
Debug ist in dem Code eine Debugfunktion, welche ich für das ganze Programm verwendet habe. Das kannste ohne weiteres entfernen. Der Code ist noch sehr unausgereift. Also, entwickel ihn mal weiter. :wink:
P.S.: Ich glaube im Forum, befindet sich noch ein besserer Code. Kannst ja mal die Suchfunktion bemühen.
Entwickler-Ecke.de based on phpBB
Copyright 2002 - 2011 by Tino Teuber, Copyright 2011 - 2025 by Christian Stelzmann Alle Rechte vorbehalten.
Alle Beiträge stammen von dritten Personen und dürfen geltendes Recht nicht verletzen.
Entwickler-Ecke und die zugehörigen Webseiten distanzieren sich ausdrücklich von Fremdinhalten jeglicher Art!