1

i'm trying to write the imdb rating in a cell after the movie name for my movie list. unfortunately i can't get the imdb value saved.

Sub seleniumtest()
Dim RS
Set GC = New Selenium.ChromeDriver
GC.Start
GC.Get ("https://www.imdb.com/title/tt0993840/")
Set RS = GC.FindElementByCss("[class='AggregateRatingButton__RatingScore-sc-1ll29m0-1 iTLWoV']")

RS should be 5.8

As an Error i get:

Element not found for Css=.AggregateRatingButton__RatingScore-sc-1ll29m0-1 iTLWoV```

I think it is because of the space
3
  • Do you need to use selenium? Commented Jul 9, 2021 at 11:09
  • with internet explorer it doesn't work very well, and i read everywhere that selenium is the successor Commented Jul 9, 2021 at 14:32
  • Are you just after this value or another value? There doesn't seem to be a need for a browser at all to get most data from this page. There is at least one far quicker way to get that info. Commented Jul 9, 2021 at 15:02

2 Answers 2

1

You can use the below css :

span[class^='AggregateRatingButton']

like in code :

Debug.Print  GC.FindElementByCss("span[class^='AggregateRatingButton']").Text
Sign up to request clarification or add additional context in comments.

6 Comments

now I have no more error thanks :) but I do not have the 5.8 in RS. i also can't format it as string because an object is required.
You can use .Attribute ('innerHTML') on that above command and print to see if you get desire output
then I get "error compiling": Sytsnax error don't i also have to put a "RS =" in front of it?
That's just a reference right ? You can put it in front and then try to print RS and see if that works
Can you try this Debug.Print GC.FindElementByCss("span[class^='AggregateRatingButton']").Text ? I have updated the answer as well
|
1

You could avoid using a browser altogether and issue an XHR request and then regex out the required value from the return string. Should be a lot faster. If you are after more data from the page, nearly all of it can be retrieved with a single XHR request and slightly different handling of response text.

Public Sub GetRating()
    Dim http As Object, re As Object, url As String, s As String
    
    Set http = CreateObject("MSXML2.XMLHTTP"): Set re = CreateObject("VBScript.RegExp")
    url = "https://www.imdb.com/title/tt0993840/"
    re.Pattern = "{""aggregateRating"":([0-9.]+),"
    re.Global = True
    
    With http
        .Open "GET", url, False
        .setRequestHeader "User-Agent", "Mozilla/5.0"
        .send
        s = .responseText
        Set matches = re.Execute(s)
   End With
   
   Debug.Print matches(matches.Count - 1).SubMatches(0)

End Sub

3 Comments

that's pretty cool, and it's pretty damn fast. thanks a lot i didn't know that. unfortunately it is still nciht for me, because I find out the link before via google i'm feeling lucky, and then write the value in the excel list. so the value to the left of the cell is entered in google, - an im feeling lucky search query is started - which usually hits imdb - and then I read out the value.
there should be a loop before which looks something like this: Set http = CreateObject("MSXML2.XMLHTTP"): Set re = CreateObject("VBScript.RegExp") url = "google.com/search?btnI=1&q=imdb " & Cells(x, 1).Value re.Pattern = "{""imdb"":([0-9.]+)," re.Global = True I think I'll look at the XHR again :)
but that would be the same problem for all other answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.