我构建一个基本的Web爬虫从网站中提取信息。
为此,我创建了simple_html_dom.php
。
现在我的代码就像
<?php
include_once('simple_html_dom.php');
$target_url = "http://www.example.com/";
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('a') as $link) {
echo $link->href."<br />";
}
?>
我收到错误
解析错误:语法错误,意外':'in 第3行的C:\ xampp \ htdocs \ test \ test.php
plz help是什么问题
答案 0 :(得分:0)
你的双引号和单引号很奇怪。我怀疑是键盘问题..
PHP接受的正常单引号为',您的'
PHP接受的正常双引号是“,你的”
您的固定代码是:
<?php
include_once('simple_html_dom.php');
$target_url = "http://www.xyz.com/";
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('a') as $link){
echo $link->href."<br />";
}
&GT;
答案 1 :(得分:0)
我认为你的字符串只是使用了错误的引号。
错误:“string“
右:"string"
或者:'string'
请检查您的键盘设置
答案 2 :(得分:0)
您似乎已复制粘贴此代码。您的代码块中的单引号和双引号错误。将“
更改为"
,将’
更改为'
。您正确的代码块是: -
<?php
include_once('simple_html_dom.php');
$target_url = "http://www.example.com/";
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('a') as $link) {
echo $link->href."<br />";
}
?>
答案 3 :(得分:0)
根据您粘贴的内容,您没有使用适当的双引号来封装字符串$target_url = "http://www.xyz.com/"
;使用"