-
Notifications
You must be signed in to change notification settings - Fork 172
/
Springer.py
62 lines (36 loc) · 1.1 KB
/
Springer.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# coding: utf-8
# In[9]:
import requests
import os
import pandas as pd
import time
os.chdir('d:/python')
# In[4]:
def scrape(url):
session=requests.Session()
page=session.get(url,verify=False)
return page.content
# In[5]:
def main():
#get textbook list
content=scrape('https://resource-cms.springernature.com/springer-cms/rest/v1/content/17858272/data/v4')
f=open('textbook.xlsx','wb')
f.write(content)
f.close
df=pd.ExcelFile('textbook.xlsx').parse('eBook list')
#iterate through all books but it will take a long ass time
for i in range(len(df)):
name=df['Book Title'][i]
url=df['OpenURL'][i]
print(name)
prefix='https://rd.springer.com/content/pdf/'
postfix=df['DOI URL'][i].split('http://doi.org/')[-1].replace('/','%2F')
url=prefix+postfix+'.pdf'
time.sleep(5)
content=scrape(url)
f=open(f'{name}.pdf','wb')
f.write(content)
f.close
if __name__ == "__main__":
main()