工作任务突然下来了,好多,考虑了一下想使用python登陆获取数据,然后和本地系统数据对比做一下,但是我发现我使用requesrs模拟登陆竟然登陆失败,百思不得其解,只好向大家求助。
网址: http://61.178.81.162:8888/LQL_OA/login.aspx
因为保密的原因,账号和密码不能提供,请大家谅解,如果因为客观条件不能够提供代码,请达人提供一下思路,谢谢!
# -*- encoding: utf-8 -*-
import requests
from PIL import Image
from StringIO import StringIO
from lxml import etree
from lxml import *
import lxml.html
import urllib2
import lxml.html as H
txtUserName = ""
txtPassword = ""
yz = ''#验证码字符串
signin_url = "http://61.178.81.162:8888/LQL_OA/login.aspx"
login_url = "http://61.178.81.162:8888/LQL_OA/Index.aspx"
LoginCode_url ="http://61.178.81.162:8888/LQL_OA/LoginCode.aspx"
user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)"
Referer = signin_url
__EVENTARGUMENT=''
__EVENTTARGET = 'lkbut_OK'
__VIEWSTATE = ''
__VIEWSTATEGENERATOR='17AE1282'
login = requests.get(signin_url)
doc = H.document_fromstring(login.content)
__VIEWSTATE = doc.xpath('//*[@id="__VIEWSTATE"]/@value')[0]
print __VIEWSTATE
#下载验证码图片
yz_LoginCode = requests.get(LoginCode_url)
im = Image.open(StringIO(yz_LoginCode.content))
im.show()
yz = input("Please input your Code:\n")
#登陆网页
headers = {"User-Agent": user_agent,'Referer': Referer,}
logininfo = {"txtUserName": txtUserName,
"txtPassword": txtPassword,
"yz": yz,
"__EVENTARGUMENT":__EVENTARGUMENT,
"__EVENTTARGET":__EVENTTARGET ,
"__VIEWSTATE":__VIEWSTATE,
"__VIEWSTATEGENERATOR":__VIEWSTATEGENERATOR,
}
liudong_session = requests.Session()
signin_req =
liudong_session.post(signin_url,
data=logininfo,
headers=headers,
)
print signin_req.encoding
content = open('content.html', 'w')
content.write(signin_req.content.replace('/LQL_OA','http://61.178.81.162:8888/LQL_OA'))
content.close()
info = liudong_session.get(login_url)
info_content = open('info_content.html', 'w')
info_content.write(info.content.replace('/LQL_OA','http://61.178.81.162:8888/LQL_OA'))
info_content.close()
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/161431
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.