forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrawl_google_scholar_citation.py
More file actions
Latest commit
42 lines (36 loc) · 1.06 KB
/
Copy pathcrawl_google_scholar_citation.py
File metadata and controls
42 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Get the citation from google scholar
using title and year of publication, and volume and pages of journal.
"""
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "beautifulsoup4",
# "httpx",
# ]
# ///
importhttpx
frombs4importBeautifulSoup
defget_citation(base_url: str, params: dict) ->str:
"""
Return the citation number.
"""
soup=BeautifulSoup(
httpx.get(base_url, params=params, timeout=10).content, "html.parser"
)
div=soup.find("div", attrs={"class": "gs_ri"})
anchors=div.find("div", attrs={"class": "gs_fl"}).find_all("a")
returnanchors[2].get_text()
if__name__=="__main__":
params= {
"title": (
"Precisely geometry controlled microsupercapacitors for ultrahigh areal "
"capacitance, volumetric capacitance, and energy density"
),
"journal": "Chem. Mater.",
"volume": 30,
"pages": "3979-3990",
"year": 2018,
"hl": "en",
}
print(get_citation("https://scholar.google.com/scholar_lookup", params=params))