shahin
Active Member
I've written some code using IE and Xmlhttp requests (separately) to get the Imdb "rating" and The "rating count" against some movie names. At this moment I can achieve the same using IE because I've already completed it but in case of performing the same using xmlhttp request, things become slightly problematic. The codes I've pasted below are working ones but you see that the second request (within xmlhttp request) has been performed using hardcoded "url" which I do not wish to comply. This is the very portion "tt0078346" in the second url changing upon each different search. I don't understand where it is generated from. If i could somehow manage to generate this number correlated to each search then my goal is fulfilled. Hope, somebody will take a look.
Using IE (working one):
Using xmlhttp (working but with hardcoded portion in the url):
Although it is running smoothly, i would like to shake off the hardcoded portion "tt0078346" from the second requests.
Btw, the second "http request" I used in my script to perform the click programmatically.
Using IE (working one):
Code:
Sub imd_data()
Dim IE As New InternetExplorer, html As HTMLDocument, ele As Object
With IE
.Visible = True
.navigate "http://www.imdb.com/"
Do Until .readyState = READYSTATE_COMPLETE: Loop
Set html = .document
End With
html.getElementById("navbar-query").Value = "Blood Diamond"
html.getElementById("navbar-submit-button").Click
Application.Wait Now + TimeValue("00:00:05")
html.getElementsByClassName("result_text")(0).getElementsByTagName("a")(0).Click
Do Until IE.readyState = READYSTATE_COMPLETE: Loop
For Each ele In html.getElementsByClassName("flatland")
With ele.getElementsByClassName("imdbRating")(0).getElementsByClassName("ratingValue")
If .Length Then r = r + 1: Cells(r, 1) = .Item(0).innerText
End With
With ele.getElementsByClassName("imdbRating")(0).getElementsByClassName("small")
If .Length Then Cells(r, 2) = .Item(0).innerText
End With
Next ele
IE.Quit
End Sub
Using xmlhttp (working but with hardcoded portion in the url):
Although it is running smoothly, i would like to shake off the hardcoded portion "tt0078346" from the second requests.
Code:
Sub imd_data()
Dim HTTP As New XMLHTTP60, html As New HTMLDocument
Dim argstr As String, ele As Object
argstr = "ref_=nv_sr_fn&q=Superman$s=all"
With HTTP
.Open "GET", "http://www.imdb.com/find?" & argstr, False
.send
End With
With HTTP
.Open "GET", "http://www.imdb.com/title/tt0078346/?ref_=fn_al_tt_1", False ''wish to kick out this "tt0078346" from this hardcoded link
.send
html.body.innerHTML = .responseText
End With
For Each ele In html.getElementsByClassName("imdbRating")
Debug.Print ele.FirstChild.FirstChild.innerText
Debug.Print ele.FirstChild.NextSibling.innerText
Next ele
End Sub
Btw, the second "http request" I used in my script to perform the click programmatically.
Last edited: