Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Placer une page WEB dans un fichier

2 réponses
Avatar
Raymond Fournier
Bonjour a tous,
Je voudrais récupérer le contenu d'une page web dans un fichier.
J'ai fais un programme pour géré ma liste d'épicerie, et je voudrais
comparer les items de ma liste avec les épiceries ou je vais pour savoir s’il
y en a en spécial.

Merci. Raymond Fournier

2 réponses

Avatar
Jean-marc
Raymond Fournier wrote:
Bonjour a tous,
Je voudrais récupérer le contenu d'une page web dans un fichier.
J'ai fais un programme pour géré ma liste d'épicerie, et je voudrais
comparer les items de ma liste avec les épiceries ou je vais pour
savoir s'il y en a en spécial.

Merci. Raymond Fournier



Hello,

tu as une API toute prête pour ça:
Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA"
(ByVal pCaller As Long, ByVal szUrl As String, ByVal szFileName As String,
ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

On peut l'habiller un peu, c'est plus commode:

Function DownloadPage(ByVal url As String, ByVal FileName As String) As
Boolean
Dim done As Boolean
Dim value As Long

On Error Resume Next

done = True
If Dir$(FileName) <> "" Then
Kill FileName
End If
value = URLDownloadToFile(0, url, FileName, 0, 0)
If Dir$(FileName) = "" Then
done = False
End If
DownloadPage = done
End Function

Et si tu veux d'un seul coup ton fichier dans un buffer:

Public Function readFromFile(ByVal szFileName As String, ByRef buf As
String) As Boolean
Dim f As Integer

On Error GoTo readFromFile_err

f = FreeFile
Open szFileName For Binary As #f
buf = Space$(LOF(f))
Get #f, , buf
Close #f
readFromFile = True

readFromFile_ok:
Exit Function
readFromFile_err:
Resume readFromFile_ok
End Function


Et voila :-)

--
Jean-marc Noury (jean_marc_n2)
Microsoft MVP - Visual Basic
mailto: remove '_no_spam_' ;
FAQ VB: http://faq.vb.free.fr/
Avatar
Raymond Fournier
"Jean-marc" wrote:

Raymond Fournier wrote:
> Bonjour a tous,
> Je voudrais récupérer le contenu d'une page web dans un fichier.
> J'ai fais un programme pour géré ma liste d'épicerie, et je voudrais
> comparer les items de ma liste avec les épiceries ou je vais pour
> savoir s'il y en a en spécial.
>
> Merci. Raymond Fournier

Hello,

tu as une API toute prête pour ça:
Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA"
(ByVal pCaller As Long, ByVal szUrl As String, ByVal szFileName As String,
ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

On peut l'habiller un peu, c'est plus commode:

Function DownloadPage(ByVal url As String, ByVal FileName As String) As
Boolean
Dim done As Boolean
Dim value As Long

On Error Resume Next

done = True
If Dir$(FileName) <> "" Then
Kill FileName
End If
value = URLDownloadToFile(0, url, FileName, 0, 0)
If Dir$(FileName) = "" Then
done = False
End If
DownloadPage = done
End Function

Et si tu veux d'un seul coup ton fichier dans un buffer:

Public Function readFromFile(ByVal szFileName As String, ByRef buf As
String) As Boolean
Dim f As Integer

On Error GoTo readFromFile_err

f = FreeFile
Open szFileName For Binary As #f
buf = Space$(LOF(f))
Get #f, , buf
Close #f
readFromFile = True

readFromFile_ok:
Exit Function
readFromFile_err:
Resume readFromFile_ok
End Function


Et voila :-)

--
Jean-marc Noury (jean_marc_n2)
Microsoft MVP - Visual Basic
mailto: remove '_no_spam_' ;
FAQ VB: http://faq.vb.free.fr/





Merci Jean-marc, J'ai été très occuper ce week-end et je n'ais pas pu
réponde avant. Je suis nouveau avec VB et l'Internet, alors je vais regarder
ton code avec grand intéret.

Raymond Fournier


Raymond Fournier