@@ -24,12 +24,15 @@ def __init__(self, **kwargs):
2424 @filterinvalidproxies
2525 def refreshproxies (self ):
2626 # initialize
27- self .candidate_proxies , session = [], requests .Session ()
28- headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36' }
29- (resp := session .get ('https://iproyal.com/_astro/FreeProxyListTable.CHEnT7E3.js' , headers = headers , timeout = 60 )).raise_for_status ()
30- headers ['Authorization' ] = re .search (r'Authorization:\s*(["\'])(.*?)\1' , resp .text ).group (2 )
27+ self .candidate_proxies , session , headers = [], requests .Session (), {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36' }
28+ # dynamically obtain current FreeProxyListTable js file
29+ (resp := session .get (self .homepage , headers = headers , timeout = 60 )).raise_for_status ()
30+ js_path = re .search (r'["\'](?P<path>/_astro/FreeProxyListTable\.[^"\']+\.js)["\']' , resp .text ).group ('path' )
31+ (resp := session .get ('https://iproyal.com' + js_path , headers = headers , timeout = 60 )).raise_for_status ()
32+ if (m := re .search (r'Authorization\s*:\s*(["\'])(.*?)\1' , resp .text )): headers ['Authorization' ] = m .group (2 )
33+ headers .update ({'Origin' : 'https://iproyal.com' , 'Referer' : 'https://iproyal.com/' })
3134 # obtain proxies
32- for page in range (1 , self .max_pages + 1 ):
35+ for page in range (1 , self .max_pages + 1 ):
3336 params = {"fields[0]" : "ip" , "fields[1]" : "port" , "fields[2]" : "protocol" , "fields[3]" : "country" , "fields[4]" : "city" , "pagination[page]" : page , "pagination[pageSize]" : 100 }
3437 try : (resp := session .get ('https://cms.iproyal.com/api/free-proxy-records' , headers = self .getrandomheaders (base_headers = headers ), params = params , timeout = 60 )).raise_for_status (); data_items = resp .json ()['data' ]
3538 except Exception : continue
0 commit comments