Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve text data from off of ASPX page

Status
Not open for further replies.

JRB-Bldr

Programmer
May 17, 2001
3,281
US
My apologies if this is already somewhere in the forum and I just could not find it.

Let's begin by assuming that accessing a certain .ASPX webpage will display a text 'report' if a previous web operation was executed.
If that operation was not executed, there will be a blank page displayed.

I need to create a VFP program to 'hit' the .aspx page and 'retrieve' the page contents into a string.
I can then 'interrogate' the string to determine if it is blank or not and then do the appropriate actions.

Since I have not done this type of thing before, what I need is assistance/suggestions/advice towards developing the program to accomplish the task.
1. How to 'hit' the webpage​
2. How to retrieve its contents into a string variable (or other object)​

Any advice/suggestions you might have would be greatly appreciated.

Thanks,
JRB-Bldr






 
Sounds like a job for the Internet Transfer Control. This is one of the ActiveX controls that come with VFP. You drop it on a form, change its name to something meaningful (say iNet), then call its OpenURL() method:

[tt]lcPage = THISFORM.iNet.OpenURL(< address of ASPX page goes here >)[/tt]

You can then access the contents from the variable, lcPage.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Just to be clear .... What you will get in lcPage is the contents of the page as seen by the browser (that is, your "report"). I assume that this is what you want. You don't get the actual ASPX code.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike - you are correct, I do not want the ASPX code. Instead I want the displayed 'content' of the page.
And I thank you for your suggestion.

While waiting for the reply I did find another possible solution (or variety of solutions) at:
How to really simply read a web page from Visual FoxPro ( )​

When I tested the code it seemed to work reasonably well.
However I might try your suggestion since it appears even simpler.

Thanks,
JRB-Bldr
 
Try this code. It shows you how to get elements from a web page
in this case it will save the text ( no html tags ) to a file,
and next the tables content as delimited tab.



Code:
************************************************
* this will extract from a web page:
* all text 
* tables data as delimited data 
* Marco Plaza
************************************************

url='[URL unfurl="true"]http://www.w3schools.com/html/html_tables.asp'[/URL]

oform=createobject('formexp')

with oform.explorer as shell.explorer.2

    .navigate(url)

    do while .readystate # 4 or .busy
        doevents
    enddo

    tc=.document.getelementsbytagname('table')

* will get all the text:   
    strtofile(.Document.body.innertext,'pageTextContent.txt')
    modify file pageTextContent.txt

endwith



messagebox('found '+transform(tc.length)+' tables ',0)


#define tab chr(9)

set textmerge to 'datafromHtmlTables.txt' noshow
set textmerge on

for each table in tc

\***************TABLE****************
    crows=table.getelementsbytagname('tr')
    for each tablerow in crows
        ccells=tablerow.getelementsbytagname('td')
        for each cell in ccells
            \\<<cell.InnerText>><<TAB>>
        endfor
    endfor
endfor

set textmerge off
set textmerge to

modify file datafromhtmltables.txt


********************************************
define class formexp as form
    add object explorer as sexplorer
enddefine
********************************************

********************************************
define class sexplorer as olecontrol
    oleclass ='shell.explorer.2'
enddefine
********************************************
 
Anything, that loads a URL can be used, eg URLDownloadToFile: [URL unfurl="true"]http://www.news2news.com/vfp/?function=268[/url]
To load into memory I'd rather use

Code:
loRequest = Createobject('MsXml2.XmlHttp')
loRequest.Open("GET", "[URL unfurl="true"]http://www.tek-tips.com",[/URL] .F.) && or whatever URL, eg [URL unfurl="true"]http://...../..../some.aspx[/URL]
loRequest.Send(.Null.)
? Left(loRequest.ResponseText,200)

Bye, Olaf.
 
Thanks to everyone for their suggestions.

The code I ended up using (before I got your other suggestions) is using URLDownloadToFile().
I download the URL contents into a file and then use FILETOSTR() to move it into a variable for subsequent use.
Currently that approach is doing what I need.

However now that I have some alternative approaches to try, I will try them and see if one works better than another.

Thanks,
JRB-Bldr
 
The advantage of URLDownloadToFile(), compared to the method I suggested, is that it doesn't require any external components to be installed. If it meets your needs, I would go with that.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
MsXml2.XmlHttp may depend on a certain MSXML version, but otherwise it doesn't create a file, you can directly work with ResponseText. Dis disadvantage is, the class does build a DOM and parses XML into a REsponseXML property at the same time. As you say you can play with the alternatives and see what fits best.

Bye, Olaf.
 
MSXML is pretty broadly available. It's on any Windows PC that has IE going back to (I think) IE4 (3?). For simply grabbing text from a page it's probably the least heavy lift.
 
There is an alias name Microsoft.XMLHttp for the class. It's not really the version independent class name, but I think it should work from Win95 to Win10, too.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top