OriginLab Corporation - Data Analysis and Graphing Software - 2D graphs, 3D graphs, Contour Plots, Statistical Charts, Data Exploration, Statistics, Curve Fitting, Signal Processing, and Peak Analysis                     
 

2.14.1.13 web2file

Brief Information

Copy web page to file

Command Line Usage

web2file url:="www.originlab.com" fname:="c:\test.txt" // Save webpage to a txt file

web2file url:="www.originlab.com" fname:="c:\test.html" response:=2 maxtime:=20 // Save webpage to a html file

Variables

Display
Name
Variable
Name
I/O
and
Type
Default
Value
Description
URL url

Input

string

url$
Specify address of the web page to be copied.
File Name fname

Input

string

fname$
Specify the name of the downloading file. Usually, you need to specify the address in which to store the file. For example, you could use C:\test.txt to specify the name and the address together. If not specify the address of the file, the file will be put on the user file folder.
Maximum Transfer Time (sec, 0 = no limit) maxtime

Input

int

0
Specify the maximum transfer time. Please note that the time includes the time to wait the server to find/ generate the file and the time to transfer the file. The default setting is 0, which means the time is unlimited.
Response Timeout (sec) response

Input

int

30
In some situation, the server may need time to find/ generate file when the URL is requested. This parameter allows you to set the response timeout to wait the server to find/ generate the file.

Description

This X-function is used to copy a web page to a local file.

Examples

This example downloads a file from the internet using http and place it in the UFF and then imports the file into the active sheet.

// Copy web file to local file.
string fname$="%Y_tmp_webdata.txt";
string url$="http://hadobs.metoffice.com/hadcrut3/diagnostics/global/nh+sh/annual";
web2file;
if( exist(fname$) > 0 )
{
  impASC;
  del -f "%(fname$)"; // remove file once done.
}
else
  ty "Failed to copy web file to local file.";

This example showed it also works for https,

string fname$="%Y_tmp_webdata.csv";
string url$="https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=MSFT&apikey=demo&datatype=csv";
web2file;
if( exist(fname$) > 0 )
{
  impCSV options.Sparklines:=0 options.HeaderLines.SubHeaderLines:=1 options.HeaderLines.LongNames:=1;
  del -f "%(fname$)"; // remove file once done.
  wks.col1.SetFormat(4, 22, yyyy'-'MM'-'dd);
}

This example downloads the OriginLab logo image from the OriginLab website and places it in the UFF and then imports that image into a new matrix sheet.

string fname$="%Y_tmp_logo.png";
string url$="http://www.originlab.com/images/header_logo.png";
web2file;
if( exist(fname$) > 0 )
{
  win -t matrix;
  impImage;
  del -f "%(fname$)"; // remove file once done.
}
else
  ty "Failed to copy web file to local file.";

Related X-Functions

 

© OriginLab Corporation. All rights reserved.