+ Reply to Thread
Results 1 to 10 of 10

Parse internet explorer tree structure via vba.

  1. #1
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Parse internet explorer tree structure via vba.

    Hi,

    Please copy this link into your internet explorer address bar:

    http://www.google.com/trends/explore#cmpt=q

    At the lower left there is something like a tree structure called "All Categories". By clicking on any node in this tree you will recognize the changed url the browsers address bar. I want to create a list via vba that looks like this:

    All Categories | http://www.google.com/trends/explore#cmpt=q
    Arts & Entertainment | http://www.google.com/trends/explore#cat=0-3&cmpt=q
    Celebrities & Entertainment New | http://www.google.com/trends/explore#cat=0-3-184&cmpt=q
    Comics & Animation | http://www.google.com/trends/explore#cat=0-3-316&cmpt=q
    ...

    How do I parse / read this object???

    Thank you very much!
    Lloyd

  2. #2
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Parse internet explorer tree structure via vba.

    Any ideas?

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Parse internet explorer tree structure via vba.

    Are you after them all or only elements of a certain "depth"? IE do you want everything form that list and all sublists or just 1 level of sublist?

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Parse internet explorer tree structure via vba.

    Ok, I'm going to assume you want them all:
    Please Login or Register  to view this content.
    Last edited by Kyle123; 02-07-2013 at 12:43 PM.

  5. #5
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Parse internet explorer tree structure via vba.

    Hi Kyle,

    I have to apologize for the delayed feedback. For some reason I am not able to login on excelforum via internet explorer anymore. I now use chrome. Your code throws this error Run-time-error '-2147012894 (80072ee2)': Automation error in line
    Please Login or Register  to view this content.
    Lloyd

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Parse internet explorer tree structure via vba.

    Odd, but try replacing:
    Please Login or Register  to view this content.
    With:
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Parse internet explorer tree structure via vba.

    Hi Kyle,

    thank you very much!

    I don't want to overstay your time, but as I am a total newbie to embedded java, I want to please for a short explanation that this code is doing in detail.

    I like to do some modifications in the result list:

    The current solution lists the child nodes before parent nodes, I like to have the opposite order in the result list.

    Thank you very much!

    Lloyd

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Parse internet explorer tree structure via vba.

    No problem Lloyd, the code is JavaScript rather than java. The bulk of the work is done by the getall function, it's recursive so may well takes some getting your head round, the problem with having the headings first is that a lot of the child categories are in more than one parent, so where would they sit - in the list I gave you, they're only listed once, would you want them listed in each parent category?

    for reference, the javascript code un minified is:
    PHP Code: 
    var getall = function(categories,out) {
        var 
    out out || {};
        var 
    category undefined;
        var 
    ref;
        for (var 
    key in categories) {
            if (
    key == 'name') {
                
    category categories[key];
                continue;
            }
            if (
    key == 'id') {
                
    ref categories[key];
                continue;
            }
            var 
    mytype typeof(categories[key]);
            if (
    mytype == 'object'
            
    || mytype == 'array') {
                
    out=getall(categories[key],out);
            };
        }
        if (
    category !== undefined) {
            if (
    out[category] === undefined) {
                
    out[category] = [];
            }

           
    out[category].push(ref);
        }
        return (
    out);


  9. #9
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Parse internet explorer tree structure via vba.

    Kyle, you are right. I wasn't aware of the redundant elements.
    I am happy with this solution.
    Thank you very very much!

    Lloyd

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Parse internet explorer tree structure via vba.

    Glad it helped. as a word of warning for the future, google ain't easy to get data from through automation. It's down to how they build their web applications, a lot of the content is built through javascript so you need to know where to look to find what you're after. 99/100 times you'd be better off looking for an alternative source of data if you need to parse it automatically from a web page

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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