Solved

Copy displayed web page text with vba

Posted on 2014-12-03
7
2,100 Views
Last Modified: 2014-12-07
I need to copy the displayed text from a web page to a string.  The text is generated by the web page and not available directly from the source.  I need to obtain with vba code the same result I would get from manually selecting the entire web page text, copying it to clipboard, then pasting it into notepad.  I am using MS Office 2014 (Access).
0
Comment
Question by:riverguy
7 Comments
 
LVL 32

Expert Comment

by:Stefan Hoffmann
Comment Utility
You need to automate your web browser to copy the text from the DOM.
0
 

Author Comment

by:riverguy
Comment Utility
ste5an, thanks for the answer.  I'm not familiar with using DOM.  Would you mind giving me an example.  The information I want is not available in the source HTML, but is obtained by embedded javascript within it.   The web page is a movie schedule at http://www.fandango.com/theaterpage-prn.aspx?tid=AAWVN&date=12%2f4%2f2014 where the date elements are included in the URL.  I want to copy the output string.
0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 150 total points
Comment Utility
You can get the HTML quite easily with the MSXML2.XMLHTTP object.  What are you doing with the "text" on the page?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:riverguy
Comment Utility
I was mistaken, the text I'm looking for is available in the source text of the web page and I can get it as you suggested with an MSXML2 object in .responseText in the HTML format.  I'll have to ferret out pulling the data from the HTML.  I'm wondering if there is an object property that represents the output text, the same text one would get with selecting and copying to the clipboard all the contents of the web page, or will it have to be parsed out node by node?  I can probably go it from here.  Thanks for the help.  I'm open to any suggestions for extracting the output text.
0
 
LVL 17

Accepted Solution

by:
vb_elmar earned 350 total points
Comment Utility
To get the entire innertext of a web page use the "Microsoft HTML Object Library"
'add a reference to Microsoft WinHttp Services 5.0
'add a reference to Microsoft HTML Object Library

Private Sub CommandButton1_Click()
    Dim Req As New WinHttpRequest
    Dim RT As String, HasData As Boolean
    Dim Doc As New HTMLDocument
    
    Req.Open "GET", "http://en.wikipedia.org/wiki/Rashmi_Gautam"
    Req.Send
    RT = Req.ResponseText

    Set Doc = New HTMLDocument
    Doc.Clear
    CallByName Doc, "Write", VbMethod, RT

    MsgBox Doc.Body.innertext
End Sub

Open in new window

0
 

Author Comment

by:riverguy
Comment Utility
Thanks, that did it.  My mistake was in not recognizing that the information was in the HTML.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now