Skip to content

Commit 910b5b0

Browse files
authored
fix get citation
1 parent c6f0440 commit 910b5b0

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

google_scholar_crawler/main.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1-
from scholarly import scholarly
2-
import jsonpickle
3-
import json
4-
from datetime import datetime
5-
import os
6-
7-
author: dict = scholarly.search_author_id(os.environ['GOOGLE_SCHOLAR_ID'])
8-
scholarly.fill(author, sections=['basics', 'indices', 'counts', 'publications'])
9-
name = author['name']
10-
author['updated'] = str(datetime.now())
11-
author['publications'] = {v['author_pub_id']:v for v in author['publications']}
12-
print(json.dumps(author, indent=2))
13-
os.makedirs('results', exist_ok=True)
14-
with open(f'results/gs_data.json', 'w') as outfile:
15-
json.dump(author, outfile, ensure_ascii=False)
16-
17-
shieldio_data = {
18-
"schemaVersion": 1,
19-
"label": "citations",
20-
"message": f"{author['citedby']}",
21-
}
22-
with open(f'results/gs_data_shieldsio.json', 'w') as outfile:
23-
json.dump(shieldio_data, outfile, ensure_ascii=False)
1+
from scholarly import scholarly, ProxyGenerator
2+
import jsonpickle
3+
import json
4+
from datetime import datetime
5+
import os
6+
7+
# Setup proxy
8+
pg = ProxyGenerator()
9+
pg.FreeProxies() # Use free rotating proxies
10+
scholarly.use_proxy(pg)
11+
12+
author: dict = scholarly.search_author_id(os.environ['GOOGLE_SCHOLAR_ID'])
13+
scholarly.fill(author, sections=['basics', 'indices', 'counts', 'publications'])
14+
name = author['name']
15+
author['updated'] = str(datetime.now())
16+
author['publications'] = {v['author_pub_id']:v for v in author['publications']}
17+
print(json.dumps(author, indent=2))
18+
os.makedirs('results', exist_ok=True)
19+
with open(f'results/gs_data.json', 'w') as outfile:
20+
json.dump(author, outfile, ensure_ascii=False)
21+
22+
shieldio_data = {
23+
"schemaVersion": 1,
24+
"label": "citations",
25+
"message": f"{author['citedby']}",
26+
}
27+
with open(f'results/gs_data_shieldsio.json', 'w') as outfile:
28+
json.dump(shieldio_data, outfile, ensure_ascii=False)
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
jsonpickle==1.4.2
2-
scholarly==1.5.1
1+
jsonpickle==4.0.5
2+
scholarly==1.7.11
3+
httpx==0.23.3

0 commit comments

Comments
 (0)