python 2.7.5 auto login
6 月 29
PyDev.nic.twbbs.org
Installed CentOS 7 (64bit) mini-install
log:
yum update -y ; yum upgpgrade -y yum install vim
REF:https://www.liquidweb.com/kb/how-to-install-pip-on-centos-7/
Step #1: Add the EPEL Repository
yum install epel-release yum -y update ; yum -y install python-pip pip install mechanize pip install --upgrade pip
建立一個以python自動登入的小程式
REF: https://blog.ephrain.net/webpython-%E4%BD%BF%E7%94%A8-mechanize-%E8%87%AA%E5%8B%95%E7%99%BB%E5%85%A5%E7%B6%B2%E7%AB%99-/
# codning: UTF-8 import mechanize br = mechanize.Browser() br.set_handle_robots(False) br.set_debug_http(True) br.set_debug_responses(True) br.set_debug_redirects(True) # Add br.addheaders = [("Accept-Language", "zh-TW,zh;q=0.8")] # Add User-Agent br.addheaders = [("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.11 5 Safari/537.36")] # Browse to login page #br.open('https://login.yahoo.com/config/login') #br.open('https://nm.udn.twbbs.org/cacti/') #br.open('https://member.pixnet.cc/login/verify') br.open('https://shopping.udn.com/mall/cus/meb/Cc1m02.inw?dc_btn_0=Func_Logon_QuickView') # Select login form #br.select_form(nr=0) br.select_form(nr=0) # Fill in username and password, submit br["dc_email_0"] = "joe.chc@udngroup.com" br["dc_pswd_0"] = "uIM106Joe" br.submit() print("#####################################################") links = br.links() print(links) member_center = [l for l in br.links() if l.url.startswith("https://shopping.udn.com/mall/cus/meb/Cc1m05")][0] # Browse to memberpage br.follow_link(member_center) webcontent = br.response().get_data() print(webcontent) #webcontent = br.response().get_data() #print(webcontent) ## Find out the link to mail #link_mail = [l for l in br.links() if l.url.startswith("http://mail.yahoo.com")][0] ## Browse to mail page #br.follow_link(link_mail) #with open("output.htm", "w") as f: #f.write(br.response().get_data())