...
This commit is contained in:
		@@ -40,114 +40,122 @@ def WaitForLogin( wbDriver, tagID ):
 | 
				
			|||||||
        except NoSuchElementException:
 | 
					        except NoSuchElementException:
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#打开driver,登录网页
 | 
					def GetSessionID(webDriver):
 | 
				
			||||||
try:
 | 
					    try:
 | 
				
			||||||
    wb_ie = webdriver.Ie(executable_path='D:/develop/sdk/python/Selenium/ie_driver/IEDriverServer.exe')
 | 
					        cookies = dict( webDriver.get_cookies()[0] )
 | 
				
			||||||
    wb_ie.get('http://10.190.48.74:8601/login.jsp')
 | 
					        return cookies['name'] + '=' + cookies['value']
 | 
				
			||||||
except:
 | 
					    except:
 | 
				
			||||||
    print('打开driver和网页时出错!')
 | 
					        return None
 | 
				
			||||||
    exit(-1)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
action = ActionChains(wb_ie)
 | 
					def ScrapRepairOrderData():
 | 
				
			||||||
bs = BeautifulSoup( wb_ie.page_source, 'html.parser')
 | 
					    #打开driver,登录网页
 | 
				
			||||||
names = bs.find_all("img", {'id':'captcha'})
 | 
					    try:
 | 
				
			||||||
 | 
					        wb_ie = webdriver.Ie(executable_path='D:/develop/sdk/python/Selenium/ie_driver/IEDriverServer.exe')
 | 
				
			||||||
 | 
					        wb_ie.get('http://10.190.48.74:8601/login.jsp')
 | 
				
			||||||
 | 
					    except:
 | 
				
			||||||
 | 
					        print('打开driver和网页时出错!')
 | 
				
			||||||
 | 
					        exit(-1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#填写登录信息
 | 
					    action = ActionChains(wb_ie)
 | 
				
			||||||
try:
 | 
					    bs = BeautifulSoup( wb_ie.page_source, 'html.parser')
 | 
				
			||||||
    captcha = wb_ie.find_element_by_id('captcha')
 | 
					    names = bs.find_all("img", {'id':'captcha'})
 | 
				
			||||||
    branchCode = wb_ie.find_element_by_id('branchCode')
 | 
					 | 
				
			||||||
    userCode = wb_ie.find_element_by_id('userCode')
 | 
					 | 
				
			||||||
    password = wb_ie.find_element_by_id('password')
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    branchCode.send_keys('3080100')
 | 
					    #填写登录信息
 | 
				
			||||||
    userCode.send_keys('588')
 | 
					    try:
 | 
				
			||||||
    password.send_keys('Kane@1982')
 | 
					       captcha = wb_ie.find_element_by_id('captcha')
 | 
				
			||||||
except NoSuchElementException:
 | 
					       branchCode = wb_ie.find_element_by_id('branchCode')
 | 
				
			||||||
    print('获取登录页面元素失败!')
 | 
					       userCode = wb_ie.find_element_by_id('userCode')
 | 
				
			||||||
    wb_ie.close()
 | 
					       password = wb_ie.find_element_by_id('password')
 | 
				
			||||||
    exit(-1)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
try:
 | 
					       #登录的循环,没错误时才继续。
 | 
				
			||||||
    WaitForLogin( wb_ie, 'captcha')
 | 
					       while True:
 | 
				
			||||||
except NoSuchElementException:
 | 
					           try:
 | 
				
			||||||
    print('浏览器异常关闭!')
 | 
					               branchCode.clear()
 | 
				
			||||||
    exit()
 | 
					               userCode.clear()
 | 
				
			||||||
 | 
					               password.clear()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#输出cookie
 | 
					               branchCode.send_keys('3080100')
 | 
				
			||||||
try:
 | 
					               userCode.send_keys('588')
 | 
				
			||||||
    cookies = wb_ie.get_cookies()
 | 
					               password.send_keys('Kane@1982')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cookie_dict = dict(cookies[0])
 | 
					               WaitForLogin( wb_ie, 'captcha')
 | 
				
			||||||
 | 
					           except Exception as e:
 | 
				
			||||||
    print( cookie_dict['name'] + '=' + cookie_dict['value'] )
 | 
					               print(e)
 | 
				
			||||||
except:
 | 
					           else:
 | 
				
			||||||
    wb_ie.close()
 | 
					               break
 | 
				
			||||||
    exit()
 | 
					    except NoSuchElementException:
 | 
				
			||||||
 | 
					        print('获取登录页面元素失败!')
 | 
				
			||||||
try:
 | 
					        wb_ie.close()
 | 
				
			||||||
    #点击统计查询
 | 
					        exit(-1)
 | 
				
			||||||
    element = wb_ie.find_element_by_xpath("//*[text()='统计查询']")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    action.move_to_element_with_offset(element, 1, 1 ).perform()
 | 
					 | 
				
			||||||
    #time.sleep(1)
 | 
					 | 
				
			||||||
    action.context_click(element).perform()
 | 
					 | 
				
			||||||
    action.click(element)
 | 
					 | 
				
			||||||
    action.perform()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    #点击送返修工单查询
 | 
					 | 
				
			||||||
    element = wb_ie.find_element_by_xpath("//*[text()='送返修工单查询']")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    action.move_to_element_with_offset(element, 1, 1 ).perform()
 | 
					 | 
				
			||||||
    #time.sleep(1)
 | 
					 | 
				
			||||||
    action.context_click(element).perform()
 | 
					 | 
				
			||||||
    action.click(element)
 | 
					 | 
				
			||||||
    action.perform()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    #time.sleep(1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    #切换iframe tabset_workOrderQuery
 | 
					 | 
				
			||||||
    wb_ie.switch_to.frame('tabset_workOrderQuery')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    #按钮
 | 
					 | 
				
			||||||
    queryButton = wb_ie.find_element_by_xpath("//*[text()='查询']")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    #日期元素
 | 
					 | 
				
			||||||
    startDateElement = wb_ie.find_element_by_id('createStartDate')
 | 
					 | 
				
			||||||
    endDateElement = wb_ie.find_element_by_id('createEndDate')
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #开始查询和抓取循环
 | 
					    #输出cookie
 | 
				
			||||||
 | 
					    sessionID = GetSessionID( wb_ie )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        #点击统计查询
 | 
				
			||||||
 | 
					        element = wb_ie.find_element_by_xpath("//*[text()='统计查询']")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        action.move_to_element_with_offset(element, 1, 1 ).perform()
 | 
				
			||||||
 | 
					        #time.sleep(1)
 | 
				
			||||||
 | 
					        action.context_click(element).perform()
 | 
				
			||||||
 | 
					        action.click(element)
 | 
				
			||||||
 | 
					        action.perform()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #点击送返修工单查询
 | 
				
			||||||
 | 
					        element = wb_ie.find_element_by_xpath("//*[text()='送返修工单查询']")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        action.move_to_element_with_offset(element, 1, 1 ).perform()
 | 
				
			||||||
 | 
					        #time.sleep(1)
 | 
				
			||||||
 | 
					        action.context_click(element).perform()
 | 
				
			||||||
 | 
					        action.click(element)
 | 
				
			||||||
 | 
					        action.perform()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #time.sleep(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #切换iframe tabset_workOrderQuery
 | 
				
			||||||
 | 
					        wb_ie.switch_to.frame('tabset_workOrderQuery')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #按钮
 | 
				
			||||||
 | 
					        queryButton = wb_ie.find_element_by_xpath("//*[text()='查询']")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #日期元素
 | 
				
			||||||
 | 
					        startDateElement = wb_ie.find_element_by_id('createStartDate')
 | 
				
			||||||
 | 
					        endDateElement = wb_ie.find_element_by_id('createEndDate')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					        #开始查询和抓取循环
 | 
				
			||||||
 | 
					        while True:
 | 
				
			||||||
 | 
					            #填写起始日期和终止日期
 | 
				
			||||||
 | 
					            startDateElement.clear()
 | 
				
			||||||
 | 
					            endDateElement.clear()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            startDateElement.send_keys('2019-11-10')
 | 
				
			||||||
 | 
					            endDateElement.send_keys('2019-12-10')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            #查询
 | 
				
			||||||
 | 
					            action.move_to_element_with_offset( queryButton, 2, 2 ).perform()
 | 
				
			||||||
 | 
					            action.click(queryButton).perform()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            #查询后等待一段时间
 | 
				
			||||||
 | 
					            #time.sleep(2)
 | 
				
			||||||
 | 
					    except NoSuchElementException:
 | 
				
			||||||
 | 
					        print('查找不到元素')
 | 
				
			||||||
 | 
					        exit(-1)
 | 
				
			||||||
 | 
					    except:
 | 
				
			||||||
 | 
					        print('页面读取错误')
 | 
				
			||||||
 | 
					        exit(-1)
 | 
				
			||||||
 | 
					    finally:
 | 
				
			||||||
 | 
					        #wb_ie.close()
 | 
				
			||||||
 | 
					        None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while True:
 | 
					    while True:
 | 
				
			||||||
        #填写起始日期和终止日期
 | 
					        time.sleep(1)
 | 
				
			||||||
        startDateElement.clear()
 | 
					        print('已登录!!!')
 | 
				
			||||||
        endDateElement.clear()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        startDateElement.send_keys('2019-11-10')
 | 
					 | 
				
			||||||
        endDateElement.send_keys('2019-12-10')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        #查询
 | 
					 | 
				
			||||||
        action.move_to_element_with_offset( queryButton, 2, 2 ).perform()
 | 
					 | 
				
			||||||
        action.click(queryButton).perform()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        #查询后等待一段时间
 | 
					 | 
				
			||||||
        #time.sleep(2)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
except NoSuchElementException:
 | 
					 | 
				
			||||||
    print('查找不到元素')
 | 
					 | 
				
			||||||
    exit(-1)
 | 
					 | 
				
			||||||
except:
 | 
					 | 
				
			||||||
    print('页面读取错误')
 | 
					 | 
				
			||||||
    exit(-1)
 | 
					 | 
				
			||||||
finally:
 | 
					 | 
				
			||||||
    #wb_ie.close()
 | 
					 | 
				
			||||||
    None
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#测试代码
 | 
				
			||||||
 | 
					if __name__ == '__main__':
 | 
				
			||||||
while True:
 | 
					    ScrapRepairOrderData()
 | 
				
			||||||
    time.sleep(1)
 | 
					 | 
				
			||||||
    print('已登录!!!')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
 | 
				
			|||||||
# Visual Studio Version 16
 | 
					# Visual Studio Version 16
 | 
				
			||||||
VisualStudioVersion = 16.0.29519.181
 | 
					VisualStudioVersion = 16.0.29519.181
 | 
				
			||||||
MinimumVisualStudioVersion = 10.0.40219.1
 | 
					MinimumVisualStudioVersion = 10.0.40219.1
 | 
				
			||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "车商可视化数据管理系统", "车商可视化数据管理系统\车商可视化数据管理系统.vcxproj", "{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}"
 | 
					 | 
				
			||||||
EndProject
 | 
					 | 
				
			||||||
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "车商渠道数据采集", "..\python\车商渠道数据采集\车商渠道数据采集.pyproj", "{81F2541E-C96A-4C05-B3F5-643B25E708D5}"
 | 
					Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "车商渠道数据采集", "..\python\车商渠道数据采集\车商渠道数据采集.pyproj", "{81F2541E-C96A-4C05-B3F5-643B25E708D5}"
 | 
				
			||||||
EndProject
 | 
					EndProject
 | 
				
			||||||
Global
 | 
					Global
 | 
				
			||||||
@@ -21,32 +19,6 @@ Global
 | 
				
			|||||||
		Release|x86 = Release|x86
 | 
							Release|x86 = Release|x86
 | 
				
			||||||
	EndGlobalSection
 | 
						EndGlobalSection
 | 
				
			||||||
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
 | 
						GlobalSection(ProjectConfigurationPlatforms) = postSolution
 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Debug|Any CPU.ActiveCfg = Debug|x86
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Debug|ARM.ActiveCfg = Debug|ARM
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Debug|ARM.Build.0 = Debug|ARM
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Debug|ARM.Deploy.0 = Debug|ARM
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Debug|ARM64.ActiveCfg = Debug|ARM64
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Debug|ARM64.Build.0 = Debug|ARM64
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Debug|ARM64.Deploy.0 = Debug|ARM64
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Debug|x64.ActiveCfg = Debug|x64
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Debug|x64.Build.0 = Debug|x64
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Debug|x64.Deploy.0 = Debug|x64
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Debug|x86.ActiveCfg = Debug|x86
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Debug|x86.Build.0 = Debug|x86
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Debug|x86.Deploy.0 = Debug|x86
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Release|Any CPU.ActiveCfg = Release|x86
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Release|ARM.ActiveCfg = Release|ARM
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Release|ARM.Build.0 = Release|ARM
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Release|ARM.Deploy.0 = Release|ARM
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Release|ARM64.ActiveCfg = Release|ARM64
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Release|ARM64.Build.0 = Release|ARM64
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Release|ARM64.Deploy.0 = Release|ARM64
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Release|x64.ActiveCfg = Release|x64
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Release|x64.Build.0 = Release|x64
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Release|x64.Deploy.0 = Release|x64
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Release|x86.ActiveCfg = Release|x86
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Release|x86.Build.0 = Release|x86
 | 
					 | 
				
			||||||
		{DFAB7824-DB3C-4114-AFE8-6DBD2892C07E}.Release|x86.Deploy.0 = Release|x86
 | 
					 | 
				
			||||||
		{81F2541E-C96A-4C05-B3F5-643B25E708D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
							{81F2541E-C96A-4C05-B3F5-643B25E708D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
				
			||||||
		{81F2541E-C96A-4C05-B3F5-643B25E708D5}.Debug|ARM.ActiveCfg = Debug|Any CPU
 | 
							{81F2541E-C96A-4C05-B3F5-643B25E708D5}.Debug|ARM.ActiveCfg = Debug|Any CPU
 | 
				
			||||||
		{81F2541E-C96A-4C05-B3F5-643B25E708D5}.Debug|ARM64.ActiveCfg = Debug|Any CPU
 | 
							{81F2541E-C96A-4C05-B3F5-643B25E708D5}.Debug|ARM64.ActiveCfg = Debug|Any CPU
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user