[Python] 純文字檢視 複制代碼# encoding=utf-8
import requests
from BaseClass import config
from bs4 import BeautifulSoup
import urllib
class login(config):
def __init__(self,url):
self.data = '''__VIEWSTATE={}&txtUserName={}&Textbox1=&TextBox2={}&txtSecretCode={}&RadioButtonList1=%D1%A7%C9%FA&Button1=&lbLanguage=&hidPdrs=&hidsc='''
super(login,self).__init__(url)
def login(self,xh,pwd,yzm,cookies):
try:
data=self.data.format(self.getVaules(cookies=cookies),xh, pwd, yzm)
s=requests.session()
s.cookies=cookies
con = s.post(self.url, headers=self.headers, data=data)
if con.url==self.url:
print("驗證碼可能出現錯誤!請重新登陸")
#print(con.content.decode('gbk'))
return False,None,None,None,
else:
data=con.content
soup=BeautifulSoup(data,'html.parser',from_encoding='gbk')
xm=soup.find('span',attrs={'id':'xhxm'}).text[0:len(soup.find('span',attrs={'id':'xhxm'}))-3]
#print(xm)
return True,cookies,xh,xm
except Exception, e:
print(e.args)
print(e.message)
print e.__doc__
print(u"出現錯誤!請重新登陸")
return False,None,None,None,