Skip to content

Commit c521243

Browse files
AlfianAliMpre-commit-ci[bot]cclauss
authored
Update crawl_google_scholar_citation.py (#11655)
* Update crawl_google_scholar_citation.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Improve docstring clarity in crawl_google_scholar_citation.py Updated the docstring for clarity and fixed formatting issues. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent 2ee6d96 commit c521243

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

‎web_programming/crawl_google_scholar_citation.py‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
Get the citation from google scholar
3-
using title and year of publication, and volume and pages of journal.
2+
Get the citation from Google Scholar using the title and year of publication, and the
3+
journal volume and pages.
44
"""
55

66
# /// script
@@ -17,17 +17,29 @@
1717

1818
def get_citation(base_url: str, params: dict) -> str:
1919
"""
20-
Return the citation number.
20+
Returns the citation number for a publication based on its title, journal, volume,
21+
pages, and year of publication.
22+
23+
Parameters:
24+
- base_url: The base URL for making requests to Google Scholar.
25+
- params: A dictionary containing the publication information.
26+
27+
Returns:
28+
- A string containing the number of citations.
2129
"""
30+
# Send a GET request to the URL with the specified parameters
2231
soup = BeautifulSoup(
2332
httpx2.get(base_url, params=params, timeout=10).content, "html.parser"
2433
)
34+
# Find the div element with class 'gs_ri' that contains citation information
2535
div = soup.find("div", attrs={"class": "gs_ri"})
36+
# Find all links in the div and retrieve the third link (the citation count)
2637
anchors = div.find("div", attrs={"class": "gs_fl"}).find_all("a")
27-
return anchors[2].get_text()
38+
return anchors[2].get_text() # Return the text from the third link
2839

2940

3041
if __name__ == "__main__":
42+
# Define parameters for the publication whose citation is to be searched
3143
params = {
3244
"title": (
3345
"Precisely geometry controlled microsupercapacitors for ultrahigh areal "
@@ -37,6 +49,7 @@ def get_citation(base_url: str, params: dict) -> str:
3749
"volume": 30,
3850
"pages": "3979-3990",
3951
"year": 2018,
40-
"hl": "en",
52+
"hl": "en", # Language to be used (English)
4153
}
54+
# Call the get_citation function with the specified URL and parameters
4255
print(get_citation("https://scholar.google.com/scholar_lookup", params=params))

0 commit comments

Comments
 (0)