472,982 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,982 software developers and data experts.

Grab data from another site ! HELP ME PLEASE !

I have 2 codes below to grap data from another site. I use them to get
the data from one News site. However, when I click on some link inside
(such as :
http://www.thuthao.info/news/chitiet...5/01/3B9DB0AC/
), there are some errors, I try fix some, but hopeless. CAN ANY BODY
HELP ME ??? MUCH APPRECIATED
demo : news.thuthao.info
real site : www.vnexpress.net

Code of Index.php
----------------------------------------------------------------

<?php
function grabData($source_to_grab, $delimiter_start, $delimiter_stop,
$str_to_replace='', $str_replace='', $extra_data='') {
$fd = ""; $start_pos = $end_pos = 0;
$source_to_grab = fopen($source_to_grab, "r");
while(true) {
if($end_pos > $start_pos) {
$result = substr($fd, $start_pos, $end_pos-$start_pos);
$result .= $delimiter_stop;
break;
}//10
$data = fread($source_to_grab, 8192);
if(strlen($data) == 0) break;
$fd .= $data;
if(!$start_pos) $start_pos = strpos($fd, $delimiter_start);
if($start_pos) $end_pos = strpos(substr($fd, $start_pos),
$delimiter_stop) + $start_pos;
}
fclose($source_to_grab);
return str_replace($str_to_replace, $str_replace, $extra_data.$result);
}//19

$url = "http://vnexpress.net/Vietnam/Home/";

$delimiter_start = '<table width="100%" cellspacing=0 cellpadding=0
border=0><tr bgcolor="#CCCCCC">';
$delimiter_stop = '<td width=210 valign=top><A
href="/Vietnam/Home/buuthiep.gif" class=Normal></A>';
$web = grabData($url, $delimiter_start, $delimiter_stop, 'img src="/',
'img src="http://vnexpress.net/', '');
$web = str_replace('href="',
'href="http://www.thuthao.info/news/chitiet.php?url=', $web);
$header = '<html><head><meta http-equiv="Content-Type"
content="text/html; charset=UTF-8"><link rel="stylesheet"
href="Default.css" type="text/css"><title>NGUYEN HUYNH THU THAO
NEWS</title></head><body topmargin=3 leftmargin=0 marginheight=3
marginwidth=0>';
$footer = '</tr></table></body></html>';
$full = $header.$web.$footer;
echo '<div align=center><a href="http://news.thuthao.info">Trang
nhất</a> - <a href="http://www.thuthao.info">Trang chủ</a> - <a
href="http://forum.thuthao.info">Diễn đ*n</a></div>';
echo '<tr>&nbsp;</tr>';
echo $full;
-------------------------------------------------------------------

Code of chitiet.php
-------------------------------------------------------------------
<?php
function grabData($source_to_grab, $delimiter_start, $delimiter_stop,
$str_to_replace='', $str_replace='', $extra_data='') {
$fd = ""; $start_pos = $end_pos = 0;
$source_to_grab = fopen($source_to_grab, "r");
while(true) {
if($end_pos > $start_pos) {
$result = substr($fd, $start_pos, $end_pos-$start_pos);
$result .= $delimiter_stop;
break;
}//10
$data = fread($source_to_grab, 8192);
if(strlen($data) == 0) break;
$fd .= $data;
if(!$start_pos) $start_pos = strpos($fd, $delimiter_start);
if($start_pos) $end_pos = strpos(substr($fd, $start_pos),
$delimiter_stop) + $start_pos;
}
fclose($source_to_grab);
return str_replace($str_to_replace, $str_replace, $extra_data.$result);
}//19
$url = 'http://vnexpress.net'.$url;
$begin1 = '<table id="CContainer" border=0 cellpadding=0 cellspacing=0
width="100%">';
$begin2 = '<table width="100%" cellspacing=0 cellpadding=0 border=0>';
$delimiter_stop = '</ul>';
$web = grabData($url, $begin1, $delimiter_stop, '', '', '');
if (strlen($web) == 0) $web = grabData($url, $begin2 , $delimiter_stop,
'', '', '');
$web = str_replace('src="','src="'.$url.'/',$web);
$web =
str_replace('src="'.$url.'//','src="http://vnexpress.net/',$web);
$web = str_replace('href="',
'href="http://www.thuthao.info/news/chitiet.php?url=', $web);
$web =
str_replace('href="www.thuthao.info/news/chitiet.php?url=javascript:history.go(-1)',
'href="javascript:history.go(-1)', $web);
$header = '<html><head><meta http-equiv="Content-Type"
content="text/html; charset=UTF-8"><link rel="stylesheet"
href="Default.css" type="text/css"><title>NGUYEN HUYNH THU THAO -
NEWS</title></head><body topmargin=3 leftmargin=0 marginheight=3
marginwidth=0>';
$footer = '</td></tr><tr><td align="center"
nowrap></td></tr></table></body></html>';
$full = $header.$web.$footer;
echo '<div align=center><a href="http://news.thuthao.info">Trang
nhất</a> - <a href="http://www.thuthao.info">Trang chủ</a> - <a
href="http://forum.thuthao.info">Diễn đ*n</a></div>';
echo '<tr>&nbsp;</tr>';
echo $full;
------------------------------------------------------------------

Jul 17 '05 #1
3 2871
"Baby Blue" <da********@gmail.com> wrote in
news:11**********************@g14g2000cwa.googlegr oups.com:
I have 2 codes below to grap data from another site. I use them to get
the data from one News site. However, when I click on some link inside
(such as :
http://www.thuthao.info/news/chitiet...ress.net/Vietn
am/Kinh-doanh/2005/01/3B9DB0AC/ ), there are some errors, I try fix
some, but hopeless. CAN ANY BODY HELP ME ??? MUCH APPRECIATED
demo : news.thuthao.info
real site : www.vnexpress.net
"Baby Blue" <da********@gmail.com> wrote in
news:11**********************@g14g2000cwa.googlegr oups.com:
I have 2 codes below to grap data from another site. I use them to get
the data from one News site. However, when I click on some link inside
(such as :
http://www.thuthao.info/news/chitiet...ress.net/Vietn
am/Kinh-doanh/2005/01/3B9DB0AC/ ), there are some errors, I try fix
some, but hopeless. CAN ANY BODY HELP ME ??? MUCH APPRECIATED


Warning: fopen(http://vnexpress.nethttp://vnexpress.net/Vietnam/Kinh-
doanh/2005/01/3B9DB0AC/): failed to open stream: HTTP request failed!

That's the error message I got when I tried to visit the address you
posted. It should tell you what you really need to know, you're trying to
load an invalid URL. Somewhere before you try to load the URL, you need
to make sure that it only contains "http://vnexpress.net" once. You can
do this using str_replace.

At a glance, it looks like the problem is here:

$url = 'http://vnexpress.net'.$url;

At this point you should check to see if "http://vnexpress.net" is
already part of $url:

$url = 'http://vnexpress.net' . str_replace('http://vnexpress.net', '',
$url);

hth

--

Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fung.arg'); Web :
shaunc.com
--------------------------
|--------------------------------------------------
<http://www.phplabs.com/> | PHP scripts and thousands of webmaster
resources!
Jul 17 '05 #2
It is really works completely, Thank you very very much !!!

Jul 17 '05 #3
I dont know why, but it just ran well for a short time, now it still
has errors, can any body help me agian ?

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Baby Blue | last post by:
I have 2 code like below to grab a news website for my site. However, when I click some links (such as : http://wwww.vnexpress.net/xxx/xxxx ) inside the site which I want to grab, it has some...
5
by: Christopher Brandsdal | last post by:
Hi! I'm stuck on a little problem... I want to get te article heading-text and teaser from http://www.avisa-valdres.no and display it on another page using asp code... An example on this:...
8
by: gregory_may | last post by:
Is there a way to grab a "Screen Shot" that includes "Tool Tips"? I saw this code someplace, cant remember where. But it doesnt grab "Tool Tips". Is there a better way to do this in .net?...
3
by: Andy Kasotia | last post by:
On the client once the user clicks the Submit button....in my code the following javascript function kicks off... onclick="return SubmitForm('frmCurrBuildings', 'CurrBuildings.asp', c_iLOADNEW,...
5
by: Vanessa | last post by:
I have a question, is that any other way to retrieve data from another webpage besides using XML object? Because I am using XML object now but give me so much problems. If I used...
9
by: Alan Silver | last post by:
hello, I am writing my first real ASP.NET application, but am getting a bit confused with ADO.NEt and the best way to use it. My old method (with Classic ASP) was to have a function that you...
10
by: Jonathan Schwarz via DotNetMonster.com | last post by:
Hi folks, I am a complete newbie to ASP.NET, VB, etc... I am coming from a Cold Fusion background where it only takes me 4 lines to query a MSSQL db and display a field name. Please, how do I...
19
by: JRough | last post by:
I have used this function to create a string called $headers: function GetHeaders($file_name){ return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th> <th><a href='"....
5
by: goldenteeplanet | last post by:
void reverse( node * & s) { // NOTE: YOU CAN NOT MOVE DATA FROM ONE NODE TO ANOTHER // YOU CAN ONLY MOVE POINTERS FROM ONE NODE TO ANOTHER //...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.