-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
35 lines (22 loc) · 851 Bytes
/
main.py
File metadata and controls
35 lines (22 loc) · 851 Bytes
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
import chatgpt as cg
import json
import biosearch as ba
import csv
if __name__ == "__main__":
chat = cg.Chatbot(cg.api_Key)
term = input("what keywords you would like to search? ")
base_url = 'https://pubmed.ncbi.nlm.nih.gov/?term='+str(term)
all_articles = []
for page in range(1, 5):
if(page==1):
base_url = base_url
else:
base_url = base_url + "&page="+ str(page)
articles = ba.__crawler_article__(base_url)
all_articles.extend(articles)
csv_path = "related_articles.csv"
with open(csv_path, "w", newline="") as f:
writer = csv.DictWriter(f,fieldnames=["title","authors","pmid","link"])
writer.writeheader()
for article in all_articles:
writer.writerow(article)