Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grab content from another website daily

Here is my problem. I am creating a website which has a "news" tab. What i want on the news tab is updated content from another news website.

Is there any way to grab plain text posted on another website, post it on a news tab in my website, and update automatically when the website posts new content? Can anybody push me in the right direction so i can learn how to do this?

I know HTML very well, but lack skill in PHP and Javascript. What do i have to learn in order to pull this off?

like image 585
Brett Merrifield Avatar asked Oct 05 '22 08:10

Brett Merrifield


2 Answers

Look up Curl... it is in php. http://php.net/manual/en/book.curl.php

Here is a nice video on it, that might be related to something you're trying to pull off. http://www.youtube.com/watch?v=PvEJz6du7R0

Here is also some code, to get the source code of a website using curl.

<?php

$ch = curl_init("http://www.example-webpage.com/file.html");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);
echo $content;

?>

One more way of doing what you want, is to use an iframe within a div...

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
<!--
#container{
    width:300px;
    height:100px;
    border:1px solid #000; 
    overflow:hidden;
    margin-left:50%;
    margin-top:5%;

}
#container iframe {
    width:1000px;
    height:750px;
    margin-left:-734px;
    margin-top:-181px;   
    border:0 solid;
 }
-->
</style>

</head>
<body>

<div id="container">
<iframe src="http://www.w3schools.com/" scrolling="no"></iframe>
</div>

</body>
</html>

Some websites don't allow you to iframe their site, so this might not work. Example, you can't iframe google, youtube, yahoo, and others.

Hope this helped :D

like image 161
Brian Smith Avatar answered Oct 10 '22 02:10

Brian Smith


This book has a section that demonstrates reading of data from another website and parsing it using PHP. Chapter 10, pg 328 "Accessing other websites".

http://www.amazon.com/PHP-Advanced-Object-Oriented-Programming-QuickPro/dp/0321832183/

Though, if you're new to PHP, and advanced Book is no place to start. I would recommend either of the following to get you started down that road.

http://www.amazon.com/PHP-MySQL-Dynamic-Web-Sites/dp/0321784073/

or

http://www.amazon.com/PHP-Web-Visual-QuickStart-Guide/dp/0321733452/

You may be able to cobble together what you need using the Advanced book, but the best way to use advanced skills is to start learning as a beginner!

like image 25
Eric Avatar answered Oct 10 '22 03:10

Eric