+ Reply to Thread
Results 1 to 10 of 10

EXCEL VBA Errortrapping IE.Document.getElementsByClassName("section-result-title").Item(i)

  1. #1
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    EXCEL VBA Errortrapping IE.Document.getElementsByClassName("section-result-title").Item(i)

    Hi guys,
    I'm trying some code I found for web scraping.
    It all works but once in a while I get an error object not found or not supported
    If I click on debug and step through the code then it works until it runs into an error again, it doesn't happen all the time, just in certain situations.
    On Error Resume next doesn't do anything since it happens in the IE environment

    Is there another way to error trap this/ It looks like the section does not have the ClassName it's looking for
    Any ideas or tips are welcome
    Please Login or Register  to view this content.
    i is valid sometimes 0 sometimes 1, like I say it happens in some occasions in others it runs smoothly.
    The reason I'm asking this is that I would like to be able to run it unattended and not have an error halt it.

    Thanks for any tip or idea
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,143

    Re: EXCEL VBA Errortrapping IE.Document.getElementsByClassName("section-result-title").Ite

    And what type/level of error handling do you have selected in "Tools\Options\General\Error Trapping", the standard "... Unhandled Errors ..." ?
    Change it maybe to "on All Errors" and see if you can catch this your error (?).

  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: EXCEL VBA Errortrapping IE.Document.getElementsByClassName("section-result-title").Ite

    Okay, thanks for the tip, I've set the handling to 'on All Errors' and will test later in the day and let you know.

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: EXCEL VBA Errortrapping IE.Document.getElementsByClassName("section-result-title").Ite

    Well, I did what you asked but then all other error trapping went hay-wire.
    I decided to be patient and wait until it happend again and it did.
    When Web-scraping it throws errors with these two lines:

    Please Login or Register  to view this content.
    In the first two cases (different rows in the VBA module) it seems that the element is not present where I goes from 0 to 19 it looks like then it's no longer there


    The last ones is when the code is sent to search for the next page

    The thing is if I the On Error Resume Next or GoTo a label, the line doesn't react to it but throws the error, probably the way I address it

    Any suggestions?

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: EXCEL VBA Errortrapping IE.Document.getElementsByClassName("section-result-title").Ite

    Quote Originally Posted by porucha vevrku View Post
    And what type/level of error handling do you have selected in "Tools\Options\General\Error Trapping", the standard "... Unhandled Errors ..." ?
    Change it maybe to "on All Errors" and see if you can catch this your error (?).
    Have you read my answer? I'm still 'hunting' but no luck yet

  6. #6
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,143

    Re: EXCEL VBA Errortrapping IE.Document.getElementsByClassName("section-result-title").Ite

    1. Try to assign all objects to object variables ('set' instruction)
    Please Login or Register  to view this content.
    2. If you have conditional jumps somewhere in the code, check if they refer to code blocks with the structure 'With ... End With' (access to the 'With ... End With' block before initiating it)
    3. Are you sure you have correctly set all the required references 'Tools\References\=>?' (calling the wrong dlls ?)
    4. Do you use "connection shortcuts" (':') in the code for subsequent commands (?) - maybe in some place of the code it was interpreted as the label name for the 'GoTo' jump ?
    5. Maybe in sensitive points of your code you should additionally use the 'Err.Clear' method ?
    6. Maybe you declared some variables without a specific type and there was a type conflict with the variables ?
    7. Maybe somewhere in the code there is an assignment to the array without a specific dimension ?

    It's hard to say without the sample code ... : (

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: EXCEL VBA Errortrapping IE.Document.getElementsByClassName("section-result-title").Ite

    I'l l try that.
    What do I dimension the variable like?
    As Object ?
    The file where it all started with is this one, Google Map Scraper V3.0.xlsb
    All variables are declared, dll's etc. it all works except that I can't trap the errors correctly and this happens when there is nothing to show for the GetElements by Class and so
    Attached Files Attached Files

  8. #8
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: EXCEL VBA Errortrapping IE.Document.getElementsByClassName("section-result-title").Ite

    I played around with the Set var as you suggested
    I think it did trap errors but with a bulk routine that search for 41 items it halted about 5 times along the way

    Please Login or Register  to view this content.
    The Error Resume Next is at the start of the routine, but still it halted on btnObj.Item(I).Click
    I did notice that in the step before the Err.Number was 0 and after the debug step the Error.Number was or 424 or 91

    So the trapping didn't work.

    Any more good tips?

  9. #9
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,143

    Re: EXCEL VBA Errortrapping IE.Document.getElementsByClassName("section-result-title").Ite

    Well ... not taking into account your observations above, such a question:

    Have you tried to trace your code for the variables:

    1. 'MainSearchBar' and 'SearchButton' declared as 'Object' and not 'Variant' ?

    2. 'SearchResult', 'I', 'J' and 'L' (where is this 'L' variable in the code ?) declared as 'Long' and not 'Variant' ?

    In some cases, '.Length' property may be of the type 'Single' rather than 'Long' => 'SearchResult' => therefore sometimes it would be advisable to declare a particular type of variable at the beginning.
    Sometimes variant variables behave strangely when transforming into a specific type, e.g. for structures such as loops.

    3. 'IE' and 'NextPageElement' declared as 'Object' for late binding not for early binding (in the object class) ?

    Ps:
    It seems to me that you should construct commands differently inside the main 'For ... Next' loop for the 'CommandButton1_Click' procedure (for these conditional jump instructions).
    Last edited by mjr veverka; 03-07-2020 at 08:12 PM.

  10. #10
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: EXCEL VBA Errortrapping IE.Document.getElementsByClassName("section-result-title").Ite

    Thanks again for the information.
    True, I was wondering about the declaration of the variables.
    As I mentioned and you can see from the attache file (Post 7) it's not of may making.
    I picked this up to help someone out and started running into (for me in-consequent) errors, using the SET variable as ... has reduced these errors and only required 'human interaction' in about five hits after having listed 195 results, so it's not that bad, but it cannot be run unattended due to this.
    I'm going to take the code back to the drawing-board and see what I can do with it.
    So, thanks once again and I'm going to mark this post as solved for now.
    I'll post you a PM or append my findings to this post if I get it working without 'human intervention'
    Cheers for now and thanks again

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Need Result in "F", "T", "I", "TI", "IP", "TP" instead of "PASS" "FAIL"
    By vijubhau in forum Excel - New Users/Basics
    Replies: 11
    Last Post: 01-23-2018, 10:20 AM
  2. [SOLVED] Replace all BLANK cells in column with header title "Balance" to "0"
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-21-2014, 09:25 AM
  3. Replies: 10
    Last Post: 11-22-2013, 04:58 AM
  4. File saves "invoice" to document title. Trying to make it stop
    By Habanero Time in forum Excel General
    Replies: 0
    Last Post: 01-14-2013, 04:27 AM
  5. compare two excel sheets using macros and display the result in "true" or "false"
    By gayunana01 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-09-2012, 07:21 AM
  6. Replies: 5
    Last Post: 10-12-2010, 06:46 AM
  7. Replies: 2
    Last Post: 11-25-2006, 08:50 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1