Environment: Ubuntu 16.04
Python version 3.5+
Importrequests, lxml fromBs4ImportBeautifulSoup fromIoImportBytesio fromPILImportImageclasssimulationlogging:#Construct Data defStructure_data (self): Data= { 'Remember':' on', 'Backurl':'http://weibo.cn/1786213845/fans?vt=4', 'Backtitle':'Micro Blog', 'Trycount':"', 'Submit':'Login'} URL='http://weibo.cn/1786213845/fans?vt=4'I=requests.get (URL). Text R= BeautifulSoup (I,"lxml") url_2='http://login.weibo.cn/login/'Url_login= url_2 + str (r.find ('form', method="Post"). Get ('Action')) Password_name= R.find ('input', type="Password"). Get ('name') Username= Input ('Please enter user name:') data['Mobile'] =Username Password= Input ('Please enter your password') Data[password_name]=Password VKS= R.find_all ('input') data['VK'] = Vks[7].get ('value') data['Capid'] = Vks[8].get ('value') img= R.find ('img', alt="Please open the picture display"). Get ('src') file=Bytesio (Requests.get (IMG). Content) img=image.open (file) img.show () code= Input ('Please enter the verification code shown (not case-sensitive)') data['Code'] =Code Img.close () self.get_content (url_login, data)#get Web page content defget_content (self, Url_login, data): Request= Requests.post (Url_login, Data=data). Text R= BeautifulSoup (Request,"lxml") Print(R)if __name__=='__main__': Test=simulationlogging () test.structure_data ( )
Simple analog login for WAP version of Sina Weibo