1
아래 함수에서 제외 할 도메인 목록을 지정하고 싶습니다. 몇 가지 옵션은 무엇입니까? 제외 할 배열 컬렉션?경로 링크에서 URL을 제외 하시겠습니까?
http://baz.example.com
는 노드 세트를 테스트 할 Xpath 1.0. specification for other possible string functions를 참조하십시오 :이 XPath를 태그하기 때문에
class KeywordSearch
{
const GOOGLE_SEARCH_XPATH = "//a[@class='l']";
public $searchQuery;
public $numResults ;
public $sites;
public $finalPlainText = '';
public $finalWordList = array();
public $finalKeywordList = array();
function __construct($query,$numres=7){
$this->searchQuery = $query;
$this->numResults = $numres;
$this->sites = array();
}
protected static $_excludeUrls = array('wikipedia.com','amazon.com','youtube.com','zappos.com');//JSB NEW
private function getResults($searchHtml){
$results = array();
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = false;
@$dom->loadHTML($searchHtml);
$xpath = new DOMXpath($dom);
$links = $xpath->query(self::GOOGLE_SEARCH_XPATH);
foreach($links as $link)
{
$results[] = $link->getAttribute('href');
}
$results = array_filter($results,'self::kwFilter');//JSB NEW
return $results;
}
protected static function kwFilter($value)
{
return !in_array($value,self::$_excludeUrls);
}
+1 멋진 제이슨이 보인다. 감사! –
@Scott B 도움이 되었기 때문에 기꺼이 도와 드리겠습니다. 유용하다고 생각하시면 받아들이십시오. –
오류가 발생합니다> "두 번째 인수 인 'myFilter'는 유효한 콜백이어야합니다." –