Asked by duncanb7
at 2024-06-06 13:43:50
Point:500 Replies:4 POST_ID:828316USER_ID:11059
Topic:
PHP Scripting Language;;MySQL Server
How to extract specified data from webpaga in PHPQuestion: Since I would like to extract data everyday, so I choose to use my domain name Linux server to run server-side
PHP program to extract one my favourite page and one specified data and saving& append it to a file , for example, the following webpage with its html code at line-11 in attached Example-1 with bold number of "119.000" that is what I want to extract and save. But it is really hard since only one "Unique" patten in whole webpage which is from line-6 to line-11. Be Reminded the example webpage has morethan 300 hundred lines more than the part of code I attached in the following example.
I have through those tutorial in PHP websit, final I try by error to test which PHP method is better and easier and came up with the following code
<?php
$pattern="Code of line6-line11 before "119.000" data being extracted";
$content = file_get_contents('http://www.myfavuirte.com');
preg_match(/$pattern/(?=.*)/, $content, $match);
echo $match[0] ; /* it should "code fo line-6...line11 before "119.000"
echo $match[1] ; /* it should be the data I want "119.000"*/
The PHP code above is not working and try by error for many days
Question-1, Should I use function explore() to make the whole pages into array first
such as $ARR1=explose(" ", $content) in order to avoid many line break and space(" ") parse error issue before
using preg_match to match the pattern with the webpage content
Question-2, I try to use explore to some code, it has parse error to those code when code having char
of <,> and "1234", and try use single quatation of ' instead of "" to set $pattern='code here ', but doesn't improve at all
For example , $pattern='<table width="100%" cellpadding="0" cellspacing="1">' instead of
$pattern="<table width="100%" cellpadding="0" cellspacing="1">"...Please advise it.
Question-3, Am I going to wrong direction to extract data from webpaga? In VBA this part may be easier since we can use document.innertext to extract text first and then use string extractor function to search/locate position of the data.
But VBA coudl not run on Linux server. Is there any easier way to extract my data from webpaga,
Question-4, Could provide some example code , let me to follow,
Please kindly advse and help
Br
Ducan
PHP program to extract one my favourite page and one specified data and saving& append it to a file , for example, the following webpage with its html code at line-11 in attached Example-1 with bold number of "119.000" that is what I want to extract and save. But it is really hard since only one "Unique" patten in whole webpage which is from line-6 to line-11. Be Reminded the example webpage has morethan 300 hundred lines more than the part of code I attached in the following example.
I have through those tutorial in PHP websit, final I try by error to test which PHP method is better and easier and came up with the following code
<?php
$pattern="Code of line6-line11 before "119.000" data being extracted";
$content = file_get_contents('http://www.myfavuirte.com');
preg_match(/$pattern/(?=.*)/, $content, $match);
echo $match[0] ; /* it should "code fo line-6...line11 before "119.000"
echo $match[1] ; /* it should be the data I want "119.000"*/
The PHP code above is not working and try by error for many days
Question-1, Should I use function explore() to make the whole pages into array first
such as $ARR1=explose(" ", $content) in order to avoid many line break and space(" ") parse error issue before
using preg_match to match the pattern with the webpage content
Question-2, I try to use explore to some code, it has parse error to those code when code having char
of <,> and "1234", and try use single quatation of ' instead of "" to set $pattern='code here ', but doesn't improve at all
For example , $pattern='<table width="100%" cellpadding="0" cellspacing="1">' instead of
$pattern="<table width="100%" cellpadding="0" cellspacing="1">"...Please advise it.
Question-3, Am I going to wrong direction to extract data from webpaga? In VBA this part may be easier since we can use document.innertext to extract text first and then use string extractor function to search/locate position of the data.
But VBA coudl not run on Linux server. Is there any easier way to extract my data from webpaga,
Question-4, Could provide some example code , let me to follow,
Please kindly advse and help
Br
Ducan