Skip to content

Update crawl_google_scholar_citation.py #11655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions web_programming/crawl_google_scholar_citation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,32 @@

def get_citation(base_url: str, params: dict) -> str:
"""
Return the citation number.
Returns the citation number for a publication based on its title, journal, volume,
pages, and year of publication.

Parameters:
- base_url: The base URL for making requests to Google Scholar.
- params: A dictionary containing the publication information.

Returns:
- A string containing the number of citations.
"""
# Send a GET request to the URL with the specified parameters
soup = BeautifulSoup(
requests.get(base_url, params=params, timeout=10).content, "html.parser"
)

# Find the div element with class 'gs_ri' that contains citation information
div = soup.find("div", attrs={"class": "gs_ri"})

# Find all links in the div and retrieve the third link (the citation count)
anchors = div.find("div", attrs={"class": "gs_fl"}).find_all("a")
return anchors[2].get_text()

return anchors[2].get_text() # Return the text from the third link


if __name__ == "__main__":
# Define parameters for the publication whose citation is to be searched
params = {
"title": (
"Precisely geometry controlled microsupercapacitors for ultrahigh areal "
Expand All @@ -29,6 +44,8 @@ def get_citation(base_url: str, params: dict) -> str:
"volume": 30,
"pages": "3979-3990",
"year": 2018,
"hl": "en",
"hl": "en", # Language to be used (English)
}

# Call the get_citation function with the specified URL and parameters
print(get_citation("https://scholar.google.com/scholar_lookup", params=params))