直到这周,我才能够使用一个简单的 html dom 解析器从谷歌学者中抓取内容。(是的,我知道他们不希望人们这样做,因此没有 API)。
然而在过去的一两天里,它已经停止显示内容。尝试简单file_get_html
或 url 时出现以下错误:
服务器错误 很抱歉,在处理您的请求时似乎出现了内部服务器错误。我们的工程师已收到通知,正在努力解决此问题。请稍后再试。
我已经看到了其他问题,但解决方案大多是 R 特定的或使用 cURL。有没有人建议调整我的简单 php 函数,尤其是调用两次?还是我不走运,因为谷歌现在正在关闭这扇门?
我的代码:
<?php require_once('assets/functions/simple_html_dom.php');
$google_id = get_post_meta($post->ID, 'ecpt_google_id', true);
$google = new simple_html_dom;
$google_url = 'http://scholar.google.com/citations?user=' . $google_id . '&pagesize=10';
$older_pubs = 'http://scholar.google.com/citations?user=' . $google_id;
$google = file_get_html($google_url);
foreach($google->find('tr.gsc_a_tr') as $article) {
$item['title'] = $article->find('td.gsc_a_t a', 0)->plaintext;
$item['link'] = $article->find('a.gsc_a_at', 0)->href;
$item['pub'] = $article->find('td.gsc_a_t .gs_gray', 1)->plaintext;
$item['year'] = $article->find('td.gsc_a_y', 0)->plaintext;
?>
<p class="pub"><b><a href="http://scholar.google.com<?php echo $item['link'];?>"><?php echo $item['title']; ?></a></b></p>
<h6 class="pub"><?php echo $item['year']; ?>, <?php echo $item['pub']; ?></h6>
<?php } ?>
<p align="right"><b><a href="<?php echo $older_pubs; ?>">View Publications</a></b></p>