473,395 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Grab data from another site ! HELP ME PLEAS !

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 errors. Can any body
help me ??

Demo : news.thuthao.info
The real website : vnexpress.net

---------------------------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;
------------------------------------------------------------------
--------------------------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
0 2697

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

Similar topics

3
by: Baby Blue | last post by:
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 :...
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:...
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,...
0
by: TheCoder | last post by:
I am making a D-base with web conectivity for my class project. I have everything working but the subit button sends the data to the correct fields but afterwards it wants to reproduce new blank...
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...
2
by: peter | last post by:
Hi, I have very strange situation but first description ;) I have: 1) project in VB.NET, in this f.e. 1 function: Public Function Login(ByVal UserName As String, ByVal UserPassword As...
13
by: farhaaad | last post by:
Dears, I have many feilds in my tables that are left blank for some records, If I make a sub table for it and and change those feilds to a lookup feilds so only those options are chosen which...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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...

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.