谷歌学术搜索个人资料刮掉了PHP

时间:2018-03-14 16:56:49

标签: php web-scraping simple-html-dom google-scholar

我想使用SimpleHtmlDom废弃google scholar个人资料中的出版物。

我有用于抓取项目的脚本,但问题是,我只能废弃显示的项目。
当我使用这样的网址时

  

$ HTML-> LOAD_FILE(" http://scholar.google.se/citations?user=Sx4G9YgAAAAJ&#34);

只显示了20个项目。我可以在更改网址时增加数量

  

$ HTML-> LOAD_FILE(" https://scholar.google.se/citations?user=Sx4G9YgAAAAJ&hl=&view_op=list_works&pagesize=100&#34);

设置" pagesize"属性。但问题是,100是最大数量的出版物,网页能够显示什么。 有没有办法从个人资料中删除所有项目?

2 个答案:

答案 0 :(得分:2)

你无法一次性获得所有项目,但你可以一次获得100个项目,然后获得另外100个项目,依此类推,这里是URL

https://scholar.google.com/citations?user=Sx4G9YgAAAAJ&hl=&view_op=list_works&cstart=100&pagesize=100

在上面的网址中关注 cstart 属性,假设您已经抓取了100个项目,现在您将输入cstart=100并再抓取另外100个列表然后cstart=200等等直到你得到所有的出版物。

希望这有帮助

答案 1 :(得分:0)

您必须向请求 url 传递额外的分页参数。

cstart - 参数定义结果偏移量。它跳过给定数量的结果。它用于分页。 (例如,0(默认)为第一页结果,20 为第二页结果,40 为第三页结果等)。

pagesize - 参数定义要返回的结果数。 (例如,20(默认)返​​回 20 个结果,40 个返回 40 个结果等)。要返回的最大结果数为 100。

因此,您的网址应如下所示:

<块引用>

https://scholar.google.com/citations?user=WLBAYWAAAAAJ&hl=en&cstart=100&pagesize=100

您也可以使用像 SerpApi 这样的第三方解决方案来为您执行此操作。这是一个免费试用的付费 API。

用于检索第二页结果的示例 PHP 代码(也可在其他库中使用):

require 'path/to/google_search_results';

$query = [
  "api_key" => "secret_api_key",
  "engine" => "google_scholar_author",
  "hl" => "en",
  "author_id" => "WLBAYWAAAAAJ",
  "num" => "100",
  "start" => "100"
];

$search = new GoogleSearch();
$results = $search->json($query);

示例 JSON 输出:

"articles": [
  {
    "title": "Geographic localization of knowledge spillovers as evidenced by patent citations",
    "link": "https://scholar.google.com/citations?view_op=view_citation&hl=en&user=WLBAYWAAAAAJ&cstart=100&pagesize=100&citation_for_view=WLBAYWAAAAAJ:HGTzPopzzJcC",
    "citation_id": "WLBAYWAAAAAJ:HGTzPopzzJcC",
    "authors": "AB Jaffe, M Trajtenberg, R Henderson",
    "publication": "Patents, citations, and innovations: a window on the knowledge economy, 155-178, 2002",
    "cited_by": {
      "value": 18,
      "link": "https://scholar.google.com/scholar?oi=bibs&hl=en&cites=8561816228378857607",
      "serpapi_link": "https://serpapi.com/search.json?cites=8561816228378857607&engine=google_scholar&hl=en",
      "cites_id": "8561816228378857607"
    },
    "year": "2002"
  },
  {
    "title": "IPR, innovation, economic growth and development",
    "link": "https://scholar.google.com/citations?view_op=view_citation&hl=en&user=WLBAYWAAAAAJ&cstart=100&pagesize=100&citation_for_view=WLBAYWAAAAAJ:70eg2SAEIzsC",
    "citation_id": "WLBAYWAAAAAJ:70eg2SAEIzsC",
    "authors": "AGZ Hu, AB Jaffe",
    "publication": "Department of Economics, National University of Singapore, 2007",
    "cited_by": {
      "value": 17,
      "link": "https://scholar.google.com/scholar?oi=bibs&hl=en&cites=7886734392494692167",
      "serpapi_link": "https://serpapi.com/search.json?cites=7886734392494692167&engine=google_scholar&hl=en",
      "cites_id": "7886734392494692167"
    },
    "year": "2007"
  },
  ...
]

查看documentation了解更多详情。

免责声明:我在 SerpApi 工作。

相关问题