Hi, ChatGPT! Make a python code using google scholar api to parse the results of search…
- User
Hi, ChatGPT! Make a python code using google scholar api to parse the results of search request such as title, abstract, date, authors, doi and make json file. The input parameter is search request
- Assistant
Unfortunately, Google Scholar doesn't provide an official API. However, you can use a third-party package called
scholarlyto achieve similar functionality. To use it, first install it using:pip install scholarlyThen you can use the following Python code as an example:
import json from scholarly import scholarly def search_scholar(query, output_file='results.json'): search_query = scholarly.search_pubs(query) results = [] for result in search_query: paper = {} paper['title'] = result['bib']['title'] paper['authors'] = result['bib']['author'] if 'abstract' in result['bib']: paper['abstract'] = result['bib']['abstract'] paper['year'] = result['bib']['pub_year'] if 'doi' in result: paper['doi'] = result['doi'] results.append(paper) with open(output_file, 'w', encoding='utf-8') as f: json.dump(results, f, ensure_ascii=False, indent=4) search_term = "machine learning" search_scholar(search_term)