leuthrick
Gebruiker
- Lid geworden
- 17 sep 2008
- Berichten
- 454
hallo,
is dit een legaal script?
ik vond het via google.
en dit is een ander script
en dit hoort bij het script hier boven
en dan nog dit script(weer een ander script)
alleen deze scand alleen maar de rss feeds
alvast bedankt
is dit een legaal script?
ik vond het via google.
PHP:
<?php
error_reporting(E_ALL);
class spider {
function __construct($bot,$input_file,$output_file='',$output_ext='.txt') {
$this->useragent = $bot;
$this->input_f = $input_file;
$this->output_f = $output_file;
$this->output_ext = $output_ext;
$this->logs_dir = 'spider';
$this->counter = 0;
if(!file_exists('spider')) {
echo '<font color="blue">Map aangemaakt</font><br>';
mkdir("spider", 0777);
}
$this->score_out();
}
function score_out() {
if(!file_exists($this->input_f)) {
exit('<font color="red">'.htmlentities($this->input_f).' is niet aangemaakt</font>');
} else {
$word = file($this->input_f);
if(count($word)!=$this->counter) {
$this->url = $word[$this->counter];
$this->url = str_replace(PHP_EOL,'', $this->url);
$this->counter++;
if($this->get_links()) {
echo '<font color="green">'.htmlentities($this->url).' is succesvol aangemaakt en gespidert</font><br>';
$this->score_out();
} else {
echo '<font color="red">'.htmlentities($this->url).' is niet gespidert</font><br>';
$this->score_out();
}
}
}
}
function auth(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
function get_links(){
preg_match('/[^.]+\.[^.]+$/', $this->url, $name);
$name = str_replace('/','_',$name[0]);
$url_afk = $this->logs_dir.'/'.$this->output_f.$name.$this->output_ext;
if(file_exists($url_afk)) {
return false;
} else {
preg_match_all('#href="(.+?)"#si',$this->auth(),$func);
foreach ($func[1] as $item => $value){
$fh = fopen($url_afk, 'a');
fwrite($fh, sprintf("%s\r\n", $value ));
fclose($fh);
}
return true;
}
}
}
$bot = "test";
$spider = new spider($bot,'links.txt');
?>
en dit is een ander script
PHP:
<?php
/* Database connectie */
// Include de benodigde functies
include('functions/spider.php');
// Bepaal de links op de homepage
getLinks("http://www.google.nl");
// Volg tot drie keer toe de nieuw gevonden links
for ($i = 1; $i <= 3; $i++){
controleerPaginas();
}
/* Database sluiten */
?>
en dit hoort bij het script hier boven
PHP:
<?php
/*
Deze functie haalt de tekst van een pagina op.
*/
function getBron($url){
$useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$bestand = curl_exec($ch);
curl_close($ch);
return $bestand;
}
/*
Deze functie haalt de links uit een tekst.
*/
function getLinks($url){
$pagina = getBron($url);
$tag_lijst = array ();
$tag_lijst = explode(">", $pagina);
$links = array();
$regs = array();
while (list ($id, $htmlTag) = each($tag_lijst)){
if (stristr($htmlTag, "href")) {
preg_match("/(href)\s*=\s*[\'\"]?(([[a-z]{3,5}:\/\/(([.a-zA-Z0-9-])+(:[0-9]+)*))*([+:%\/\?~=&;\\\(\),._ a-zA-Z0-9-]*))(#[.a-zA-Z0-9-]*)?[\'\" ]?(\s*rel\s*=\s*[\'\"]?(nofollow)[\'\"]?)?/i", $htmlTag, $regs);
$links[] = $regs[2];
}
}
return stopLinksInDatabase($url, $links);
}
/*
Deze functie stopt de gevonden links in de database. Als er nieuwe pagina's
bij die links zitten, wordt dat ook opgeslagen.
*/
function stopLinksInDatabase($url, $links){
global $site;
while (list ($id, $link) = each($links)){
// Als link begint met een /, $site ervoor zetten
if (substr($link, 0, 1) == "/"){
$link = $site . $link;
}
// Als link begint met www, http:// er voor zetten
if (substr($link, 0, 3) == "www"){
$link = "http://" . $link;
}
// Laatste / weg indien aanwezig
if (substr($link, strlen($link) - 1, 1) == "/"){
$link = substr($link, 0, strlen($link) - 1);
}
if (strlen(trim($link)) > 0){
// Kijk of de nieuwe pagina al in de database zit
$result = mysql_query(" SELECT *
FROM paginas
WHERE url = '" . $link . "'") or die (mysql_error());
if (mysql_num_rows($result) == 0){
mysql_query(" INSERT INTO paginas
(url, gespidered)
VALUES ('" . $link . "', '0')") or die (mysql_error());
}
// Kijk of de link al in de database zit
$result = mysql_query(" SELECT *
FROM pagina_links
WHERE url = '" . $url . "'
AND link = '" . $link . "'") or die (mysql_error());
if (mysql_num_rows($result) == 0){
mysql_query(" INSERT INTO pagina_links
(url, link)
VALUES ('" . $url . "', '" . $link . "')") or die (mysql_error());
}
}
}
return true;
}
/*
Deze functie zorgt ervoor dat alle pagina's die nog niet gespidered
zijn gespidered worden.
*/
function controleerPaginas(){
$result = mysql_query(" SELECT *
FROM paginas
WHERE gespidered = '0'") or die (mysql_error());
while ($obj = mysql_fetch_object($result)){
getLinks($obj->url);
}
return true;
}
mysql_connect("localhost", "dbname", "dbpassword") or die (mysql_error());
mysql_select_db("tbnaam") or die (mysql_error());
$site = "http://www.site.nl";
// Bepaal de links op de homepage
getLinks("http://www.site.nl");
// Volg tot 3 keer toe de nieuw gevonden links
for ($i = 1; $i <= 3; $i++){
controleerPaginas();
}
mysql_close();
?>
en dan nog dit script(weer een ander script)
PHP:
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'On');
# Original PHP code by Chirp Internet: www.chirp.com.au
# Please acknowledge use of this code by including this header.
function robots_allowed($url, $useragent=false)
{
# parse url to retrieve host and path
$parsed = parse_url($url);
$agents = array(preg_quote('*'));
if($useragent) $agents[] = preg_quote($useragent);
$agents = implode('|', $agents);
# location of robots.txt file
$robotstxt = @file('http://'.$parsed['host'].'}/robots.txt');
if(!$robotstxt) return true;
$rules = array();
$ruleapplies = false;
foreach($robotstxt as $line) {
# skip blank lines
if(!$line = trim($line)) continue;
# following rules only apply if User-agent matches $useragent or '*'
if(preg_match('/User-agent: (.*)/i', $line, $match)) {
$ruleapplies = preg_match('/('.$agents.')/i', $match[1]);
}
if($ruleapplies && preg_match('/Disallow:(.*)/i', $line, $regs)) {
# an empty rule implies full access - no further tests required
if(!$regs[1]) return true;
# add rules that apply to array for testing
$rules[] = preg_quote(trim($regs[1]), '/');
}
}
foreach($rules as $rule) {
# check if page is disallowed to us
if(preg_match('/^'.$rule.'/', $parsed['path'])) return false;
}
# page is not disallowed
return true;
}
# Einde Chirp's code
function get_rss_feeds( $url ) {
ini_set('user_agent', 'UserAgentName (http://www.jouwsite.nl)');
if(!robots_allowed($url, "UserAgentName")) {
return false;
}
$pattern = '~<link.*>~siU';
$subject = file_get_contents($url);
$matches = array();
preg_match_all( $pattern, $subject, $matches );
$pattern = '~(\w+)="(.*)"~iU';
$attributes = array();
$feeds = array();
foreach ( $matches[0] as $match ) {
preg_match_all( $pattern, $match, $attributes );
$rsslink = array();
foreach ( $attributes[1] as $key => $attribute ) {
$rsslink[$attribute] = $attributes[2][$key];
}
if ( $rsslink['type'] == 'application/rss+xml' ) {
$feeds[] = $rsslink;
}
}
return $feeds;
}
print '<pre>';
print_r( get_rss_feeds( 'http://www.webreus.nl' ) );
?>
alleen deze scand alleen maar de rss feeds
alvast bedankt
Laatst bewerkt: