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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Information from a Web Page

Status
Not open for further replies.

Deleco

Programmer
Joined
Feb 25, 2002
Messages
109
Location
GB
Hi,

I would like to read some information from a webpage and store it as a csv file (comma seperated file). The web page is an external page (not one of my own). Is there anyway of doing this using php or any other language.

Any help would be appreciated
Regards
Deleco
 
So you want to download some page from some internet server, get some data from it and store the data in csv file, right? You probably can do it also with PHP but it would be much faster to use C++. This can be done in whatever language you want, because the language only need to be able to read and write to/from files and thats the feature of all programming languages (except JS and other client side scripting languages).
 
You can do this using the file function of php. I haven't done this myself so I can't offer you the benefit of my experience but the php manual is stuffed full of useful stuff.

MrBelfry
 
Hi, Thanks for the info. It sounds from what you have said that i would need ftp access to the file. I have not got this, it is just a web page that i would like to take information off...

Is this still possible without FTP access to the file.

Regards
Deleco
 
If there are no legal issues with the site you are accessing, try the following to start out with...

Code:
<?PHP

$fd=fopen(&quot;[URL unfurl="true"]http://www.yourwebsite.com/index.html&quot;,&quot;r&quot;);[/URL]
while ($line=fgets($fd,6000))
 { $alltext.=$line; }
fclose ($fd);

//MAKE RELATIVE IMAGE PATHS ABSOLUTE
$alltext= ereg_replace (&quot;src=\&quot;../&quot;, &quot;src=\&quot;[URL unfurl="true"]http://www.yourwebsite.com/images/&quot;,[/URL] $alltext);

//change HTML table divisions to commas and new lines:
$alltext= ereg_replace (&quot;</tr><tr>&quot;, &quot;\n&quot;, $alltext);
$alltext= ereg_replace (&quot;</td><td>&quot;, &quot;\,&quot;, $alltext);

//YOUR OUTPUT IS $alltext
print $alltext;

?>


The example above is to copy the entire page (graphic references and all else. You will need to tinker with ereg_replace to kill text that is not needed in the table (such as HTML header, etc...)

Once you strip out that junk, you can drop this at the end of the script to spit out the CSV file...

Code:
<?php
header(&quot;Content-type: application/vnd.ms-excel&quot;);
header(&quot;Content-disposition: attachment; filename=&quot;myfile.csv&quot;);
print $alltext;
?>



- - picklefish - -

Why is everyone in this forum responding to me as picklefish?
 
Hi,

I Will give that a go tonight and let you know the results ASAP....

Regards
Dean
 
The PHP CURL functions also allow you to retrieve pages from other servers using all kinds of protocols.
Have you checked if the site you are accessing offers a RSS feed of what you are looking for?
The manual for CURL:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top