mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-09 16:38:50 +00:00
[GoogleSearchBridge] Update bridge (#1869)
This commit is contained in:
parent
669e92357a
commit
fe042305e4
@ -24,25 +24,35 @@ class GoogleSearchBridge extends BridgeAbstract {
|
|||||||
));
|
));
|
||||||
|
|
||||||
public function collectData(){
|
public function collectData(){
|
||||||
$html = '';
|
$header = array('Accept-language: en-US');
|
||||||
|
$html = getSimpleHTMLDOM($this->getURI(), $header)
|
||||||
$html = getSimpleHTMLDOM($this->getURI());
|
or returnServerError('No results for this query.');
|
||||||
|
|
||||||
$emIsRes = $html->find('div[id=res]', 0);
|
$emIsRes = $html->find('div[id=res]', 0);
|
||||||
|
|
||||||
if(!is_null($emIsRes)) {
|
if(!is_null($emIsRes)) {
|
||||||
foreach($emIsRes->find('div[class=g]') as $element) {
|
foreach($emIsRes->find('div[class~=g]') as $element) {
|
||||||
|
|
||||||
$item = array();
|
$item = array();
|
||||||
|
|
||||||
$t = $element->find('a[href]', 0)->href;
|
$t = $element->find('a[href]', 0)->href;
|
||||||
$item['uri'] = htmlspecialchars_decode($t);
|
$item['uri'] = htmlspecialchars_decode($t);
|
||||||
$item['title'] = $element->find('h3', 0)->plaintext;
|
$item['title'] = $element->find('h3', 0)->plaintext;
|
||||||
$item['content'] = $element->find('span[class=aCOpRe]', 0)->plaintext;
|
$resultComponents = explode(' — ', $element->find('div[data-content-feature=1]', 0)->plaintext);
|
||||||
|
$item['content'] = $resultComponents[1];
|
||||||
|
|
||||||
|
if(strpos($resultComponents[0], 'day') === true) {
|
||||||
|
$daysago = explode(' ', $resultComponents[0])[0];
|
||||||
|
$item['timestamp'] = date('d M Y', strtotime('-' . $daysago . ' days'));
|
||||||
|
} else {
|
||||||
|
$item['timestamp'] = $resultComponents[0];
|
||||||
|
}
|
||||||
|
|
||||||
$this->items[] = $item;
|
$this->items[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
usort($this->items, function($a, $b) {
|
||||||
|
return $a['timestamp'] < $b['timestamp'];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getURI() {
|
public function getURI() {
|
||||||
@ -50,7 +60,7 @@ class GoogleSearchBridge extends BridgeAbstract {
|
|||||||
return self::URI
|
return self::URI
|
||||||
. 'search?q='
|
. 'search?q='
|
||||||
. urlencode($this->getInput('q'))
|
. urlencode($this->getInput('q'))
|
||||||
. '&num=100&complete=0&tbs=qdr:y,sbd:1';
|
. '&hl=en&num=100&complete=0&tbs=qdr:y,sbd:1';
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getURI();
|
return parent::getURI();
|
||||||
|
Loading…
Reference in New Issue
Block a user