Home > other >  Python climb the apple App Store use the latest version after a period of time to climb the content
Python climb the apple App Store use the latest version after a period of time to climb the content

Time:11-02

The code
HeadersList=[{' the user-agent ':' Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360 se '},
{' the user-agent ':' Mozilla/5.0 (Macintosh; Intel Mac OS X 10 _11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36 '},
{' the user-agent ':' Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3314.0 Safari/SE 2. 537.36 X 1.0 MetaSr '},
{' the user-agent ':' Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36 '}
]

Def getHtmlList (url) : headers=headersList [random. Randint (0, len (headersList) - 1)] # headers=headersList [3] attempts=0 success=False while attempts & lt; 5 and not success: try: r=requests. Get (url, headers=headers, timeout=100) success=True return r except: time. Sleep (15) print (time, ctime ()) print (" failure "+ url) +=1 if attempts (attempts==5) : break def get_apple_lastest_version () : res_apple=getHtmlList (' https://apps.apple.com/cn/app/zhi-wu-da-zhan-jiang-shi2/id639516529 ') res_apple. Encoding=" utf-8 "apple_pattern=" version [2-9] [4-9] [0-9] [0-9]?

" Apple_pattern_2="[2-9] [4-9] [0-9] [0-9]?" Apple_version=re. The.findall (apple_pattern res_apple. Text, flags=0) if (len (apple_version)==0) : file_temp="C: \ \ temp20191023 \ \ error. TXT" data_temp=open (file_temp, 'w +) print (res_apple. Text file=data_temp) data_temp. Close () return "0.0.0" apple_version=re. The.findall (apple_pattern_2, apple_version [0], flags=0) apple=apple_version [0] return apple

Once every 60 ~ 120 s reading, after a period of time to get the wrong HTML

<meta charset="utf-8" & gt; <meta HTTP - equiv="X - UA - Compatible" content="IE=edge" & gt; <meta name="viewport" content="width=device - width, initial - scale=1, the viewport - fit=cover" & gt; <meta name="web-experience-app/config/environment" content="%7B%22appVersion%22%3A1%2C%22modulePrefix%22%3A%22web-experience-app%22%2C%22environment%22%3A%22production%22%2C%22rootURL%22%3A%22/%22%2C%22locationType%22%3A%22history-hash-router-scroll%22%2C%22historySupportMiddleware%22%3Atrue%2C%22contentSecurityPolicyMeta%22%3Atrue%2C%22contentSecurityPolicy%22%3A%7B%22default-src%22%3A%5B%22%27none%27%22%5D%2C%22img-src%22%3A%5B%22%27self%27%22%2C%22http%3A//*.mzstatic.com%22%2C%22*.mzstatic.com%22%2C%22*.apple.com%22%2C%22*.googleusercontent.com%22%2C%22data%3A%22%5D%2C%22style-src%22%3A%5B%22%27self%27%22%2C%22%27unsafe-inline%27%22%2C%22*.apple.com%22%5D%2C%22font-src%22%3A%5B%22%27self%27%22%2C%22http%3A//*.apple.com%22%2C%22https%3A//*.apple.com%22%5D%2C%22medi

What is situation... What should I do... ? Give everyone a great god to a solution

CodePudding user response:

Def get_apple_lastest_version () :
Res_apple=getHtmlList (' https://apps.apple.com/cn/app/zhi-wu-da-zhan-jiang-shi2/id639516529 ')
Res_apple. Encoding="utf-8"
Apple_pattern="version [2-9] [4-9] [0-9] [0-9]?

"
Apple_pattern_2="[2-9] [4-9] [0-9] [0-9]?"
Apple_version=re. The.findall (apple_pattern res_apple. Text, flags=0)
If (len (apple_version)==0) :
File_temp="C: \ \ temp20191023 \ \ error. TXT"
Data_temp=open (file_temp, 'w' + ')
Print (res_apple. Text file=data_temp)
Data_temp. Close ()
Return "0.0.0"

Apple_version=re. The.findall (apple_pattern_2, apple_version [0], flags=0)
Apple=apple_version [0]
The return of apple

CodePudding user response:


HeadersList=[{' the user-agent ':' Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360 se '},
{' the user-agent ':' Mozilla/5.0 (Macintosh; Intel Mac OS X 10 _11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36 '},
{' the user-agent ':' Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3314.0 Safari/SE 2. 537.36 X 1.0 MetaSr '},
{' the user-agent ':' Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36 '}
]


Def getHtmlList (url) :
Headers=headersList [random randint (0, len (headersList) - 1)]
# headers=headersList [3]
Attempts=0
Success=False
While attempts & lt; 5 and the not success:
Try:
R=requests. Get (url, headers=headers, timeout=100)
Success=True
Return r
Except:
Time. Sleep (15)
Print (time, ctime ())
Print (" failure "+ url)
Attempts +=1
If (attempts==5) :
break
  • Related