I'm beginner of php, I'm making simple program, and that use some crawling web site (not private information). The result that I expected is HTML CODE, like a
<html><head><title>blabla blabla</title></head>...................
But I checked the result, the screen shown up. not a raw code, for example,
include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->fetch("http://stackoverflow.com/");
echo $snoopy->results;
How to I get information to HTML Code? And Do you have another good parsing library in PHP? (like a beautifulsoup on Python, and Jsoup on Java)
** The result of above code : not a html code, but screen **
答案 0 :(得分:1)
要使用浏览器查看源代码而不是呈现HTML,最后一行应该是:
echo htmlspecialchars($snoopy->results);
答案 1 :(得分:0)
If you want to fetch the html from the URL you can do this simple do this by file_get_contents function of php.
$url = 'http://stackoverflow.com/';
$html = file_get_contents($url);
echo $url;
答案 2 :(得分:0)
这很简单
// Add snoopy class and initiate it
require "snoopy/Snoopy.class.php";
$snoopy = new Snoopy;
// THis fetches the html
$snoopy->fetch("http://www.php.net/");
$text = $snoopy->results;
// This fetches the text with html tags stripped
$snoopy->fetchtext("http://www.php.net/");
$text = $snoopy->results;
// This fetches all the links
$snoopy->fetchlinks('http://www.php.net/');
$linksarray = $snoopy->results;
史努比对我很有用。所以希望有所帮助