[英]simple_html_dom not finding my element
我正在嘗試通過亞馬遜的價格進行練習。
<?php
require('simple_html_dom.php');
$get = $_GET['id'];
$get_url = 'http://www.amazon.co.uk/s/field-keywords='.$get;
echo $get_url;
// Retrieve the DOM from a given URL
$html = file_get_html($get_url);
foreach($html->find('li[class=newp]') as $e)
echo $e->plaintext . '<br>';
我嘗試了一些不同的方法:
li [class = newp]
。價錢
ul [class = rsltL]
但是它什么也沒返回,我在做什么錯呢?
我也嘗試返回標題:
.lrg.bold
嘗試過Xpath,什么都沒有。
謝謝
您的代碼很好。 您的PHP設置很可能是罪魁禍首。
放
error_reporting(E_ALL);
ini_set('display_errors', '1');
在您的php腳本的開頭,看看它是否打印出任何有用的錯誤。
另外,請注意,simple_html_dom在內部使用file_get_contents()
函數來獲取頁面內容。 因此,您可能需要運行file_get_contents($get_url)
看看會發生什么。
如果該功能不起作用,那么絕對是您的PHP設置。 在這種情況下,建議您在標題中啟動另一個與此問題相關的線程。
但是,這可能會有所幫助: PHP file_get_contents在localhost上不起作用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.