【问题标题】:Google Scholar Server Error HTML ParserGoogle Scholar 服务器错误 HTML 解析器
【发布时间】:2015-11-18 21:24:19
【问题描述】:

直到这周,我才能够使用一个简单的 html dom 解析器从谷歌学者中抓取内容。 (是的,我知道他们不希望人们这样做,因此没有 API)。

但在过去一两天内,它已停止显示内容。尝试简单的file_get_html 或 url 时出现以下错误:

服务器错误我们很抱歉,但似乎出现了 处理您的请求时出现内部服务器错误。我们的工程师 已收到通知并正在努力解决问题。请尝试 稍后再来。

我见过其他的questions,但解决方案大多是 R 特定的或使用 cURL。有没有人建议调整我的简单 php 函数,尤其是调用两次?还是我不走运,因为 Google 现在正在关闭这扇门?

我的代码:

<?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>

【问题讨论】:

  • 你真的应该问谷歌......不幸的是

标签: php html-parsing internal-server-error google-scholar


【解决方案1】:

如果不接受 cookie,就无法访​​问 Google 学者。 如果您尝试使用 curl/wget/... 访问,则会发生“服务器错误”

尝试接受 cookie,对于 curl/php,请参阅: Google Server gives a server error with the first request in private browsing mode

然后加载页面两次(第一次接受 cookie 和服务器错误,第二次获得内容。)

【讨论】:

  • 谢谢!我在答案中使用了代码 sn-p,效果很好!但是,没有办法强制用户刷新页面,不是吗?
  • 是的,有。基本上有两种方式。 (1) 页面可以加载两次,如:curl_exec($curl); // 设置 cookie $data = curl_exec($curl); // 加载真实数据或 (2):您可以为所有访问者使用一个 cookie。更改 $config['cookie_file'] = $dir 。 '/饼干/' 。 md5($_SERVER['REMOTE_ADDR']) 。 '。文本文件';到 $config['cookie_file'] = '/tmp/myscholarcookie.txt';第一种解决方案可能会减慢页面的加载速度,因此在这种情况下,我更喜欢(2)。
  • 非常感谢!这解决了刷新要求。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-24
  • 1970-01-01
  • 2017-12-15
  • 1970-01-01
  • 2012-07-20
  • 1970-01-01
相关资源
最近更新 更多