-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathredirectors.py
More file actions
33 lines (23 loc) · 887 Bytes
/
redirectors.py
File metadata and controls
33 lines (23 loc) · 887 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
import re
from urllib.parse import unquote
from requests import Response
# def common_redirector(resp: Response):
# if ('<title>Handle Redirect') in resp.text and (
# matches := re.findall(r'<body><a href="(http.*?)"', resp.text)):
# return matches[0]
# return None
def sd_redirector(resp: Response):
target = None
if matches := re.findall(r'name="redirectURL" value="(http.*?)"',
resp.text):
target = unquote(matches[0])
return target if (target and 'pii' in target) else None
def wiley_redirector(resp: Response):
if 'onlinelibrary.wiley.com' in resp.url and 'epdf/' in resp.url:
doi = resp.url.split('epdf/')[-1]
return f'https://onlinelibrary.wiley.com/doi/pdfdirect/{doi}'
return None
ALL_REDIRECTORS = [
# common_redirector,
sd_redirector,
wiley_redirector]