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
| Const RepTemp = "D:\temp\"
Private Sub CmdGo_Click()
Dim IEDoc As Object
Dim objResults As Object, objH2 As Object, elem As Object
Dim livre As Object, image As Object, livreResume As Object
Dim url As String, urlLivre As String, imgName As String, titre As String
Dim title As Object, author As Object, tags As Object
Dim IE As Object
Set IE = CreateObject("InternetExplorer.application")
IE.Visible = False
On Error GoTo ErrProc
url = "https://www.bing.com/search?q=" & _
WorksheetFunction.EncodeURL("Babelio " & _
Recherche.Text)
IE.Navigate url
Do While IE.ReadyState <> 4 Or IE.Busy
DoEvents
Sleep (100)
Loop
Set IEDoc = IE.Document
Set objResults = IEDoc.getElementById("b_results")
Set objH2 = objResults.getElementsByTagName("h2")
For Each elem In objH2
Debug.Print elem.innerText
If Not elem.getElementsByTagName("a")(0) Is Nothing Then
Debug.Print elem.getElementsByTagName("a")(0).href
If InStr(1, elem.getElementsByTagName("a")(0).href, "www.babelio.com/livres") <> 0 Then
urlLivre = elem.getElementsByTagName("a")(0).href
Exit For
End If
End If
Next
If urlLivre <> "" Then
Result.Text = urlLivre
IE.Navigate urlLivre
Do While IE.ReadyState <> 4 Or IE.Busy
DoEvents
Sleep (100)
Loop
Set IEDoc = IE.Document
Set livre = IEDoc.getElementsByClassName("livre_con")(0)
Set image = livre.getElementsByTagName("img")(0)
Result.Text = "Lien image couverture : " + vbCrLf + image.src + vbCrLf
Debug.Print image.src
Set title = IEDoc.getElementsByClassName("livre_header_con")(0)
titre = title.getElementsByTagName("h1")(0).innerText
Result.Text = Result.Text + "Titre : " + titre + vbCrLf
Set author = IEDoc.getElementsByClassName("livre_auteurs")(0)
Result.Text = Result.Text + "Auteur : " + author.innerText + vbCrLf
Set tags = IEDoc.getElementsByClassName("tags")(0)
Result.Text = Result.Text + "Mots clé : " + tags.innerText + vbCrLf
Set livreResume = IEDoc.getElementsByClassName("livre_resume")(0)
Result.Text = Result.Text + "Résumé : " + livreResume.innerText + vbCrLf
' Recup image
imgName = Mid(image.src, InStrRev(image.src, "/") + 1)
URLDownloadToFile 0, image.src, RepTemp & imgName, 0, 0
Image1.Picture = LoadPicture(RepTemp & imgName)
End If
Leave:
IE.Quit
Set IE = Nothing
On Error GoTo 0
Exit Sub
ErrProc:
MsgBox Err.Description, vbCritical
Resume Leave
End Sub |
Partager