PHP 抓取工具未抓取所有元素
PHP Crawler not crawling all elements
所以我正在尝试制作一个 PHP 爬虫(供个人使用)。
该代码的作用是为发现的每个在不到 1 小时内结束但似乎存在问题的易趣拍卖项目显示 "found"。爬虫无法获取所有 span 元素并且 "remaining time" 元素是一个 .
simple_html_dom.php 已下载但未编辑。
<?php include_once('simple_html_dom.php');
//url which i want to crawl -contains GET DATA-
$url = 'http://www.ebay.de/sch/Apple-Notebooks/111422/i.html?LH_Auction=1&Produktfamilie=MacBook%7CMacBook%2520Air%7CMacBook%2520Pro%7C%21&LH_ItemCondition=1000%7C1500%7C2500%7C3000&_dcat=111422&rt=nc&_mPrRngCbx=1&_udlo&_udhi=20';
$html = new simple_html_dom();
$html->load_file($url);
foreach($html->find('span') as $part){
echo $part;
//when i echo $part it does display many span elements but not the remaining time ones
$cur_class = $part->class;
//the class attribute of an auction item that ends in less than an hour is equal with "MINUTES timeMs alert60Red"
if($cur_class == 'MINUTES timeMs alert60Red'){
echo 'found';
}
}
?>
任何答案都会有用,提前致谢
查看获取的 HTML 似乎 class alert60Red
是通过 JavaScript 设置的。所以你找不到它,因为 JavaScript 从未被执行过。
所以只搜索 MINUTES timeMs
看起来也很稳定。
<?php
include_once('simple_html_dom.php');
$url = 'http://www.ebay.de/sch/Apple-Notebooks/111422/i.html?LH_Auction=1&Produktfamilie=MacBook%7CMacBook%2520Air%7CMacBook%2520Pro%7C%21&LH_ItemCondition=1000%7C1500%7C2500%7C3000&_dcat=111422&rt=nc&_mPrRngCbx=1&_udlo&_udhi=20';
$html = new simple_html_dom();
$html->load_file($url);
foreach ($html->find('span') as $part) {
$cur_class = $part->class;
if (strpos($cur_class, 'MINUTES timeMs') !== false) {
echo 'found';
}
}
如果代码片段包含在另一个 php 文件中,或者 html 嵌入在 php 中,您的浏览器将看不到它。
所以网络抓取 api 无法检测到它。我认为最好的办法是找到 simple_html_Dom.php 的位置并尝试以某种方式抓取该文件。您甚至可能无法访问它。这很棘手。
如果你的 api 有这个功能,你也可以尝试通过 Id 查找?
所以我正在尝试制作一个 PHP 爬虫(供个人使用)。 该代码的作用是为发现的每个在不到 1 小时内结束但似乎存在问题的易趣拍卖项目显示 "found"。爬虫无法获取所有 span 元素并且 "remaining time" 元素是一个 .
simple_html_dom.php 已下载但未编辑。
<?php include_once('simple_html_dom.php');
//url which i want to crawl -contains GET DATA-
$url = 'http://www.ebay.de/sch/Apple-Notebooks/111422/i.html?LH_Auction=1&Produktfamilie=MacBook%7CMacBook%2520Air%7CMacBook%2520Pro%7C%21&LH_ItemCondition=1000%7C1500%7C2500%7C3000&_dcat=111422&rt=nc&_mPrRngCbx=1&_udlo&_udhi=20';
$html = new simple_html_dom();
$html->load_file($url);
foreach($html->find('span') as $part){
echo $part;
//when i echo $part it does display many span elements but not the remaining time ones
$cur_class = $part->class;
//the class attribute of an auction item that ends in less than an hour is equal with "MINUTES timeMs alert60Red"
if($cur_class == 'MINUTES timeMs alert60Red'){
echo 'found';
}
}
?>
任何答案都会有用,提前致谢
查看获取的 HTML 似乎 class alert60Red
是通过 JavaScript 设置的。所以你找不到它,因为 JavaScript 从未被执行过。
所以只搜索 MINUTES timeMs
看起来也很稳定。
<?php
include_once('simple_html_dom.php');
$url = 'http://www.ebay.de/sch/Apple-Notebooks/111422/i.html?LH_Auction=1&Produktfamilie=MacBook%7CMacBook%2520Air%7CMacBook%2520Pro%7C%21&LH_ItemCondition=1000%7C1500%7C2500%7C3000&_dcat=111422&rt=nc&_mPrRngCbx=1&_udlo&_udhi=20';
$html = new simple_html_dom();
$html->load_file($url);
foreach ($html->find('span') as $part) {
$cur_class = $part->class;
if (strpos($cur_class, 'MINUTES timeMs') !== false) {
echo 'found';
}
}
如果代码片段包含在另一个 php 文件中,或者 html 嵌入在 php 中,您的浏览器将看不到它。
所以网络抓取 api 无法检测到它。我认为最好的办法是找到 simple_html_Dom.php 的位置并尝试以某种方式抓取该文件。您甚至可能无法访问它。这很棘手。
如果你的 api 有这个功能,你也可以尝试通过 Id 查找?