Du befindest Dich im Archiv vom ABAKUS Online Marketing Forum. Hier kannst Du Dich für das Forum mit den aktuellen Beiträgen registrieren.

PHP Ajax Webseiten Scrapen

Ajax, Hijax, Microformats, RDF, Markup, HTML, PHP, CSS, MySQL, htaccess, robots.txt, CGI, Java, Javascript usw.
Neues Thema Antworten
Azubi
PostRank 4
PostRank 4
Beiträge: 116
Registriert: 01.07.2009, 08:47

Beitrag von Azubi » 26.03.2010, 16:11

Hallo Leutz,

ich suche eine Möglichkeit eine Ajax Seite zu parsen. Aktuell versuche ich mich mit Google, aber leider weiß ich nicht wieso mir Google nur die Startseite zurück liefert.

Gibt es eine Möglichkeit/Classe wie ich den Inhalt von Ajax bekomme? Habe mich noch nie mit Ajax beschäftigt. Könnte mir jemand sagen wie das funktioniert?

Folgender Code holt sich die Daten:

Code: Alles auswählen

<?php
require_once 'Zend/Http/Client.php';
require_once 'Zend/Http/Cookie.php';
require_once 'Zend/Http/CookieJar.php';
require_once 'Zend/Http/Exception.php';
require_once 'Zend/Http/Response.php';

class test &#123;

	public function getContent&#40;&#41; &#123;

		
		
		
		try&#123;
			//Zend Objekt wird initialisiert.
			$client = new Zend_Http_Client&#40;'http&#58;//www.google.de/#hl=de&q=e-cards.de&meta=&aq=&aqi=&aql=&oq=&gs_rfai=&fp=35e96e80585d6444'&#41;;

			//Request wird abgesetzt.
			$client->request&#40;&#41;;

			//Zend Response Objekt wird initialisiert
			$responde = Zend_Http_Response&#58;&#58;fromString&#40;$client->getLastResponse&#40;&#41;&#41;;


			//Wenn Responde fehlerhaft wird Exception geworfen.
			if &#40;$responde->isError&#40;&#41;&#41; &#123;
				$this->fehlerStatus=TRUE;
				throw new Exception&#40;"wurde folgender Fehler vom Server zurück geliefert&#58; "."\n"."Fehlercode&#58;".$responde->getStatus&#40;&#41;.' Fehlermeldung&#58;'.$responde->getMessage&#40;&#41;&#41;;
			&#125;
		
		return $this->wContent = $client->getLastResponse&#40;&#41;->getRawBody&#40;&#41;;
			
			
		&#125;catch&#40;Exception $e&#41;&#123;
			print 'In Klasse '.$e->getFile&#40;&#41;.' in Zeile '.$e->getLine&#40;&#41;.' '.$e->getMessage&#40;&#41;;
		&#125;
	

	&#125;
	
&#125;

$i = new test&#40;&#41;;
echo $i->getContent&#40;&#41;;
Folgendes bekomme ich von Google zurück:

Code: Alles auswählen

<!doctype html><html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Google</title><script>window.google=&#123;kEI&#58;"TMqsS_uYNcn6_AbGvom-Dw",kEXPI&#58;"24064",kCSI&#58;&#123;e&#58;"24064",ei&#58;"TMqsS_uYNcn6_AbGvom-Dw",expi&#58;"24064"&#125;,ml&#58;function&#40;&#41;&#123;&#125;,kHL&#58;"de",time&#58;function&#40;&#41;&#123;return&#40;new Date&#41;.getTime&#40;&#41;&#125;,log&#58;function&#40;b,d,c&#41;&#123;var a=new Image,e=google,g=e.lc,f=e.li;a.onerror=&#40;a.onload=&#40;a.onabort=function&#40;&#41;&#123;delete g&#91;f&#93;&#125;&#41;&#41;;g&#91;f&#93;=a;c=c||"/gen_204?atyp=i&ct="+b+"&cad="+d+"&zx="+google.time&#40;&#41;;a.src=c;e.li=f+1&#125;,lc&#58;&#91;&#93;,li&#58;0,Toolbelt&#58;&#123;&#125;&#125;;
window.google.sn="webhp";window.google.timers=&#123;load&#58;&#123;t&#58;&#123;start&#58;&#40;new Date&#41;.getTime&#40;&#41;&#125;&#125;&#125;;try&#123;&#125;catch&#40;u&#41;&#123;&#125;window.google.jsrt_kill=1;
var _gjwl=location;function _gjuc&#40;&#41;&#123;var e=_gjwl.href.indexOf&#40;"#"&#41;;if&#40;e>=0&#41;&#123;var a=_gjwl.href.substring&#40;e&#41;;if&#40;a.indexOf&#40;"&q="&#41;>0||a.indexOf&#40;"#q="&#41;>=0&#41;&#123;a=a.substring&#40;1&#41;;if&#40;a.indexOf&#40;"#"&#41;==-1&#41;&#123;for&#40;var c=0;c<a.length;&#41;&#123;var d=c;if&#40;a.charAt&#40;d&#41;=="&"&#41;++d;var b=a.indexOf&#40;"&",d&#41;;if&#40;b==-1&#41;b=a.length;var f=a.substring&#40;d,b&#41;;if&#40;f.indexOf&#40;"fp="&#41;==0&#41;&#123;a=a.substring&#40;0,c&#41;+a.substring&#40;b,a.length&#41;;b=c&#125;else if&#40;f=="cad=h"&#41;return 0;c=b&#125;_gjwl.href="/search?"+a+"&cad=h";return 1&#125;&#125;&#125;return 0&#125;function _gjp&#40;&#41;&#123;!&#40;window._gjwl.hash&&
window._gjuc&#40;&#41;&#41;&&setTimeout&#40;_gjp,500&#41;&#125;;
window._gjp && _gjp&#40;&#41;</script><style>td&#123;line-height&#58;.8em;&#125;.gac_m td&#123;line-height&#58;17px;&#125;form&#123;margin-bottom&#58;20px;&#125;body,td,a,p,.h&#123;font-family&#58;arial,sans-serif&#125;.h&#123;color&#58;#36c;font-size&#58;20px&#125;.q&#123;color&#58;#00c&#125;.ts td&#123;padding&#58;0&#125;.ts&#123;border-collapse&#58;collapse&#125;em&#123;font-weight&#58;bold;font-style&#58;normal&#125;.lst&#123;font&#58;17px arial,sans-serif;margin-bottom&#58;.2em;vertical-align&#58;bottom;&#125;input&#123;font-family&#58;inherit&#125;.lsb,.gac_sb&#123;font-size&#58;15px;height&#58;1.85em!important;margin&#58;.2em;&#125;#gbar,#guser&#123;font-size&#58;13px;padding-top&#58;1px !important&#125;#gbar&#123;float&#58;left;height&#58;22px&#125;#guser&#123;padding-bottom&#58;7px !important;text-align&#58;right&#125;.gbh,.gbd&#123;border-top&#58;1px solid #c9d7f1;font-size&#58;1px&#125;.gbh&#123;height&#58;0;position&#58;absolute;top&#58;24px;width&#58;100%&#125;#gbs,.gbm&#123;background&#58;#fff;left&#58;0;position&#58;absolute;text-align&#58;left;visibility&#58;hidden;z-index&#58;1000&#125;.gbm&#123;border&#58;1px solid;border-color&#58;#c9d7f1 #36c #36c #a2bae7;z-index&#58;1001&#125;.gb1&#123;margin-right&#58;.5em&#125;.gb1,.gb3&#123;zoom&#58;1&#125;.gb2&#123;display&#58;block;padding&#58;.2em .5em;&#125;.gb2,.gb3&#123;text-decoration&#58;none;border-bottom&#58;none&#125;a.gb1,a.gb2,a.gb3,a.gb4&#123;color&#58;#00c !important&#125;a.gb2&#58;hover&#123;background&#58;#36c;color&#58;#fff !important&#125;</style><script>google.y=&#123;&#125;;google.x=function&#40;e,g&#41;&#123;google.y&#91;e.id&#93;=&#91;e,g&#93;;return false&#125;;window.gbar=&#123;qs&#58;function&#40;&#41;&#123;&#125;,tg&#58;function&#40;e&#41;&#123;var o=&#123;id&#58;'gbar'&#125;;for&#40;i in e&#41;o&#91;i&#93;=e&#91;i&#93;;google.x&#40;o,function&#40;&#41;&#123;gbar.tg&#40;o&#41;&#125;&#41;&#125;&#125;;</script></head><body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b alink=#ff0000 onload="document.f.q.focus&#40;&#41;;if&#40;document.images&#41;new Image&#40;&#41;.src='/images/nav_logo8.png'" topmargin=3 marginheight=3><textarea id=csi style=display&#58;none></textarea><div id=ghead><div id=gbar><nobr><b class=gb1>Web</b> <a href="http&#58;//images.google.de/imghp?hl=de&tab=wi" onclick=gbar.qs&#40;this&#41; class=gb1>Bilder</a> <a href="http&#58;//video.google.de/?hl=de&tab=wv" onclick=gbar.qs&#40;this&#41; class=gb1>Videos</a> <a href="http&#58;//maps.google.de/maps?hl=de&tab=wl" onclick=gbar.qs&#40;this&#41; class=gb1>Maps</a> <a href="http&#58;//news.google.de/nwshp?hl=de&tab=wn" onclick=gbar.qs&#40;this&#41; class=gb1>News</a> <a href="http&#58;//www.google.de/prdhp?hl=de&tab=wf" onclick=gbar.qs&#40;this&#41; class=gb1>Shopping</a> <a href="http&#58;//mail.google.com/mail/?hl=de&tab=wm" class=gb1>E-Mail</a> <a href="http&#58;//www.google.de/intl/de/options/" onclick="this.blur&#40;&#41;;gbar.tg&#40;event&#41;;return !1" aria-haspopup=true class=gb3><u>Mehr</u> <small>&#9660;</small></a><div class=gbm id=gbi><a href="http&#58;//books.google.de/bkshp?hl=de&tab=wp" onclick=gbar.qs&#40;this&#41; class=gb2>B&#65533;cher</a> <a href="http&#58;//translate.google.de/?hl=de&tab=wT" onclick=gbar.qs&#40;this&#41; class=gb2>&#65533;bersetzer</a> <a href="http&#58;//blogsearch.google.de/?hl=de&tab=wb" onclick=gbar.qs&#40;this&#41; class=gb2>Blogs</a> <div class=gb2><div class=gbd></div></div><a href="http&#58;//www.youtube.com/?hl=de&tab=w1&gl=DE" onclick=gbar.qs&#40;this&#41; class=gb2>YouTube</a> <a href="http&#58;//www.google.com/calendar/render?hl=de&tab=wc" class=gb2>Kalender</a> <a href="http&#58;//picasaweb.google.de/home?hl=de&tab=wq" onclick=gbar.qs&#40;this&#41; class=gb2>Fotos</a> <a href="http&#58;//docs.google.com/?hl=de&tab=wo" class=gb2>Text & Tabellen</a> <a href="http&#58;//www.google.de/reader/view/?hl=de&tab=wy" class=gb2>Reader</a> <a href="http&#58;//sites.google.com/?hl=de&tab=w3" class=gb2>Sites</a> <a href="http&#58;//groups.google.de/grphp?hl=de&tab=wg" onclick=gbar.qs&#40;this&#41; class=gb2>Groups</a> <div class=gb2><div class=gbd></div></div><a href="http&#58;//www.google.de/intl/de/options/" class=gb2>und noch mehr &raquo;</a> </div></nobr></div><div id=guser width=100%><nobr><span id=gbn class=gbi></span><span id=gbf class=gbf></span><span id=gbe><a href="/url?sa=p&pref=ig&pval=3&q=http&#58;//www.google.de/ig%3Fhl%3Dde%26source%3Diglk&usg=AFQjCNFjfPavRPBJrOKJS3MB2uzhpfN6zw" class=gb4>iGoogle</a> | </span><a href="/preferences?hl=de" class=gb4>Sucheinstellungen</a> | <a href="https&#58;//www.google.com/accounts/Login?hl=de&continue=http&#58;//www.google.de/" class=gb4>Anmelden</a></nobr></div><div class=gbh style=left&#58;0></div><div class=gbh style=right&#58;0></div></div> <center><br clear=all id=lgpd><img alt="Google" height=110 src="/intl/de_de/images/logo.gif" width=301 id=logo onload="window.lol&&lol&#40;&#41;"><br><br><form action="/search" name=f><table cellpadding=0 cellspacing=0><tr valign=top><td width=25%>&nbsp;</td><td align=center nowrap><input name=hl type=hidden value=de><input name=source type=hidden value=hp><input type=hidden name=ie value="ISO-8859-1"><input autocomplete="off" maxlength=2048 name=q size=55 class=lst title="Google-Suche" value=""><br><input name=btnG type=submit value="Google-Suche" class=lsb><input name=btnI type=submit value="Auf gut Gl&#65533;ck!" class=lsb></td><td nowrap width=25% align=left><font size=-2>&nbsp;&nbsp;<a href="/advanced_search?hl=de">Erweiterte Suche</a><br>&nbsp;&nbsp;<a href="/language_tools?hl=de">Sprachtools</a></font></td></tr><tr><td align=center colspan=3><font size=-1><span style="text-align&#58;left">Suche&#58; <input id=all type=radio name=meta value="" checked><label for=all> Das Web </label> <input id=lgr type=radio name=meta value="lr=lang_de"><label for=lgr> Seiten auf Deutsch </label> <input id=cty type=radio name=meta value="cr=countryDE"><label for=cty> Seiten aus Deutschland </label> </span></font></td></tr></table></form><br><span id=footer><center id=fctr><br><font size=-1><a href="/intl/de/ads/">Werben mit Google</a> - <a href="/services/">Unternehmensangebote</a> - <a href="/intl/de/about.html">&#65533;ber Google</a> - <a href="http&#58;//www.google.com/ncr">Google.com in English</a></font><p><font size=-2>&copy;2010 - <a href="/intl/de/privacy.html">Datenschutz</a></font></p></center></span> <div id=xjsd></div><div id=xjsi><script>if&#40;google.y&#41;google.y.first=&#91;&#93;;if&#40;google.y&#41;google.y.first=&#91;&#93;;google.dstr=&#91;&#93;;google.rein=&#91;&#93;;window.setTimeout&#40;function&#40;&#41;&#123;var a=document.createElement&#40;"script"&#41;;a.src="/extern_js/f/CgJkZRICZGUgACswCjheQB0sKzAOOAwsKzAWOBcsKzAXOAYsKzAYOAUsKzAZOBksKzAlOMqIASwrMCY4CSwrMCc4BCwrMDw4AiwrMEA4DSwrMEQ4AiwrMEU4ASwrME44ASw/jIzOa-lKa9Q.js";&#40;document.getElementById&#40;"xjsd"&#41;||document.body&#41;.appendChild&#40;a&#41;;if&#40;google.timers&&google.timers.load.t&#41;google.timers.load.t.xjsls=&#40;new Date&#41;.getTime&#40;&#41;;&#125;,0&#41;;
;google.neegg=1;google.y.first.push&#40;function&#40;&#41;&#123;google.ac.b=true;google.ac.i&#40;document.f,document.f.q,'','','',&#123;a&#58;0,o&#58;0&#125;&#41;;google.History&&google.History.initialize&#40;'/'&#41;&#125;&#41;;if&#40;google.j&&google.j.en&&google.j.xi&#41;&#123;window.setTimeout&#40;google.j.xi,0&#41;;google.fade=null;&#125;</script></div><script>&#40;function&#40;&#41;&#123;
var b,d,e,f;function g&#40;a,c&#41;&#123;if&#40;a.removeEventListener&#41;&#123;a.removeEventListener&#40;"load",c,false&#41;;a.removeEventListener&#40;"error",c,false&#41;&#125;else&#123;a.detachEvent&#40;"onload",c&#41;;a.detachEvent&#40;"onerror",c&#41;&#125;&#125;function h&#40;a&#41;&#123;f=&#40;new Date&#41;.getTime&#40;&#41;;++d;a=a||window.event;var c=a.target||a.srcElement;g&#40;c,h&#41;&#125;var i=document.getElementsByTagName&#40;"img"&#41;;b=i.length;d=0;for&#40;var j=0,k;j<b;++j&#41;&#123;k=i&#91;j&#93;;g&#40;k,h&#41;;if&#40;k.complete||typeof k.src!="string"||!k.src&#41;++d;else if&#40;k.addEventListener&#41;&#123;k.addEventListener&#40;"load",h,false&#41;;k.addEventListener&#40;"error",
h,false&#41;&#125;else&#123;k.attachEvent&#40;"onload",h&#41;;k.attachEvent&#40;"onerror",h&#41;&#125;&#125;e=b-d;function l&#40;&#41;&#123;google.timers.load.t.ol=&#40;new Date&#41;.getTime&#40;&#41;;google.timers.load.t.iml=f;google.kCSI.imc=d;google.kCSI.imn=b;google.kCSI.imp=e;google.report&&google.report&#40;google.timers.load,google.kCSI&#41;&#125;if&#40;window.addEventListener&#41;window.addEventListener&#40;"load",l,false&#41;;else if&#40;window.attachEvent&#41;window.attachEvent&#40;"onload",l&#41;;google.timers.load.t.prt=&#40;f=&#40;new Date&#41;.getTime&#40;&#41;&#41;;
&#125;&#41;&#40;&#41;;
</script>
Bild