473,466 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2894
"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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.