+ Reply to Thread
Results 1 to 11 of 11

Webscraping QueryTables to variable

  1. #1
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Webscraping QueryTables to variable

    Hi,

    I have been trying to scrape a webpage without any success using xml and so have reverted to the basic QueryTable. The code below works, but I would like to speed it up by saving the results to a variable rather than writing it to the sheet then converting the range to a variable.

    Please Login or Register  to view this content.
    Also would a connection to something like ADO be a better option?

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Webscraping QueryTables to variable

    *** bump ***

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Webscraping QueryTables to variable

    *** bump ***

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Webscraping QueryTables to variable

    Hello Doc,

    Do you want the text only or do you also want the link URLs? Will this be stored to an array?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Webscraping QueryTables to variable

    Hi Leith,

    I'm trying to extract the text of Entry Terms (i.e., between "Entry Terms:" and "Previous Indexing:"). I tried using xml, but the response text didn't contain the entry terms, but when viewed in IE or the querytable, the terms come up.

    Thanks.

    abousetta

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Webscraping QueryTables to variable

    Hello Ahmed,

    This is a macro I wrote last month to scrape web pages quickly. It scrapes the data between the tag name you supply. In this case, your data in a List. The macro will return all text in all List elements. The Lists your are after are embedded in Paragraph elements.

    The macro ParseWebPage is set to the URL you posted. This macro can be modified to be more specific by not using recursion but its results would depend on the web page layout being consistent. I hope it will be of some use to you.

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 04-28-2013 at 12:49 AM.

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Webscraping QueryTables to variable

    Hi Leith,

    Yes, this is great. This is my first time to see someone use xml to create a DOM from the html text.

    I just commented out Case 1 and it works well.

    Thanks again.

    abousetta

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Webscraping QueryTables to variable

    Hello Ahmed,

    You're welcome. Well I am glad it was an easy fix.

  9. #9
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Webscraping QueryTables to variable

    Hi Leith,

    Yes, it was very helpful. Below is the final code I settled on.

    abousetta

    Please Login or Register  to view this content.

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Webscraping QueryTables to variable

    Hello Ahmed,

    Like you, it was making crazy that there weren't any examples or information on how to convert the HTML source text into HTML DOM objects. It took me about a month of research an testing to "discover" how to to it. I was beginning to believe it wasn't possible. This discovery has been a game changer and time saver for me in web data retrieval.

  11. #11
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Webscraping QueryTables to variable

    I can only imagine. In theory, I can see myself using this instead of IE for all my webscraping.

    I'm really glad you discovered this and shared it with us. If you have time, maybe start a thread in the tip and tutorials on this topic because I'm sure a lot of people will benefit from it.

    Recently I was also surprised to see that you can use Excel's webbrowser just like IE to input usernames/ passwords, click on buttons, etc. It's really depressing that no one at MS has spent the time and effort to document all of this.

    abousetta

+ 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