变更一下代码文目录名,防止qt编译中文路径出错。
This commit is contained in:
		
							
								
								
									
										163
									
								
								code/python/车商渠道数据采集/RepairOrderScrap/RepairOrderScrap.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										163
									
								
								code/python/车商渠道数据采集/RepairOrderScrap/RepairOrderScrap.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,163 @@
 | 
			
		||||
 | 
			
		||||
#送返修数据采集
 | 
			
		||||
 | 
			
		||||
import time
 | 
			
		||||
from bs4 import BeautifulSoup
 | 
			
		||||
from urllib.error import HTTPError
 | 
			
		||||
from urllib.error import URLError
 | 
			
		||||
from selenium import webdriver
 | 
			
		||||
from selenium.webdriver.common.by import By
 | 
			
		||||
from selenium.webdriver.common.action_chains import ActionChains
 | 
			
		||||
from selenium.webdriver.remote.webelement import WebElement
 | 
			
		||||
from selenium.common.exceptions import StaleElementReferenceException
 | 
			
		||||
from selenium.common.exceptions import NoSuchElementException
 | 
			
		||||
 | 
			
		||||
#常量
 | 
			
		||||
SITE_LINK = 'http://10.190.48.74:8601/'
 | 
			
		||||
IMAGE_LINK = 'images/repairMissionQuery.png'
 | 
			
		||||
BUTTON_TEXT = '统计查询'
 | 
			
		||||
MENU_TEXT = '送返修工单查询'
 | 
			
		||||
SCRAP_TIME_INTERVAL = 10 #抓取的时间间隔
 | 
			
		||||
 | 
			
		||||
def WaitForLogin( wbDriver, tagID ):
 | 
			
		||||
    waitCount = 0
 | 
			
		||||
    MaxCount = 100
 | 
			
		||||
 | 
			
		||||
    while True:
 | 
			
		||||
        #waitCount += 1
 | 
			
		||||
 | 
			
		||||
        if waitCount > MaxCount:
 | 
			
		||||
            print('骑上我的小摩托!!!!')
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        #查找id,如果找到则继续循环,如果找不到说明页面跳转了
 | 
			
		||||
        try:
 | 
			
		||||
            element = wbDriver.find_element_by_id( tagID )
 | 
			
		||||
            print('等待用户登录!')
 | 
			
		||||
            time.sleep(1)
 | 
			
		||||
        except StaleElementReferenceException:
 | 
			
		||||
            return
 | 
			
		||||
        except NoSuchElementException:
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
def GetSessionID(webDriver):
 | 
			
		||||
    try:
 | 
			
		||||
        cookies = dict( webDriver.get_cookies()[0] )
 | 
			
		||||
        return cookies['name'] + '=' + cookies['value']
 | 
			
		||||
    except:
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
def ScrapRepairOrderData():
 | 
			
		||||
    #打开driver,登录网页
 | 
			
		||||
    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)
 | 
			
		||||
    bs = BeautifulSoup( wb_ie.page_source, 'html.parser')
 | 
			
		||||
    names = bs.find_all("img", {'id':'captcha'})
 | 
			
		||||
 | 
			
		||||
    #填写登录信息
 | 
			
		||||
    try:
 | 
			
		||||
       captcha = wb_ie.find_element_by_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')
 | 
			
		||||
 | 
			
		||||
       #登录的循环,没错误时才继续。
 | 
			
		||||
       while True:
 | 
			
		||||
           try:
 | 
			
		||||
               branchCode.clear()
 | 
			
		||||
               userCode.clear()
 | 
			
		||||
               password.clear()
 | 
			
		||||
 | 
			
		||||
               branchCode.send_keys('3080100')
 | 
			
		||||
               userCode.send_keys('588')
 | 
			
		||||
               password.send_keys('Kane@1982')
 | 
			
		||||
 | 
			
		||||
               WaitForLogin( wb_ie, 'captcha')
 | 
			
		||||
           except Exception as e:
 | 
			
		||||
               print(e)
 | 
			
		||||
           else:
 | 
			
		||||
               break
 | 
			
		||||
    except NoSuchElementException:
 | 
			
		||||
        print('获取登录页面元素失败!')
 | 
			
		||||
        wb_ie.close()
 | 
			
		||||
        exit(-1)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    #输出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')
 | 
			
		||||
 | 
			
		||||
        startDateElement.send_keys('2019-11-10')
 | 
			
		||||
        endDateElement.send_keys('2019-12-10')
 | 
			
		||||
    
 | 
			
		||||
        #开始查询和抓取循环
 | 
			
		||||
        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(300)
 | 
			
		||||
    except NoSuchElementException:
 | 
			
		||||
        print('查找不到元素')
 | 
			
		||||
        exit(-1)
 | 
			
		||||
    except:
 | 
			
		||||
        print('页面读取错误')
 | 
			
		||||
        exit(-1)
 | 
			
		||||
    finally:
 | 
			
		||||
        wb_ie.close()
 | 
			
		||||
        None
 | 
			
		||||
 | 
			
		||||
    while True:
 | 
			
		||||
        time.sleep(1)
 | 
			
		||||
        print('已登录!!!')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#测试代码
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    ScrapRepairOrderData()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										1
									
								
								code/python/车商渠道数据采集/RepairOrderScrap/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								code/python/车商渠道数据采集/RepairOrderScrap/__init__.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										47
									
								
								code/python/车商渠道数据采集/车商渠道数据采集.pyproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								code/python/车商渠道数据采集/车商渠道数据采集.pyproj
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
			
		||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
 | 
			
		||||
    <SchemaVersion>2.0</SchemaVersion>
 | 
			
		||||
    <ProjectGuid>81f2541e-c96a-4c05-b3f5-643b25e708d5</ProjectGuid>
 | 
			
		||||
    <ProjectHome>.</ProjectHome>
 | 
			
		||||
    <StartupFile>RepairOrderScrap\RepairOrderScrap.py</StartupFile>
 | 
			
		||||
    <SearchPath>
 | 
			
		||||
    </SearchPath>
 | 
			
		||||
    <WorkingDirectory>.</WorkingDirectory>
 | 
			
		||||
    <OutputPath>.</OutputPath>
 | 
			
		||||
    <Name>车商渠道数据采集</Name>
 | 
			
		||||
    <RootNamespace>车商渠道数据采集</RootNamespace>
 | 
			
		||||
    <InterpreterId>Global|PythonCore|3.8</InterpreterId>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
 | 
			
		||||
    <DebugSymbols>true</DebugSymbols>
 | 
			
		||||
    <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
 | 
			
		||||
    <DebugSymbols>true</DebugSymbols>
 | 
			
		||||
    <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Folder Include="RepairOrderScrap\" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Compile Include="RepairOrderScrap\RepairOrderScrap.py">
 | 
			
		||||
      <SubType>Code</SubType>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Include="RepairOrderScrap\__init__.py">
 | 
			
		||||
      <SubType>Code</SubType>
 | 
			
		||||
    </Compile>
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <InterpreterReference Include="Global|PythonCore|3.8" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
 | 
			
		||||
  <!-- Uncomment the CoreCompile target to enable the Build command in
 | 
			
		||||
       Visual Studio and specify your pre- and post-build commands in
 | 
			
		||||
       the BeforeBuild and AfterBuild targets below. -->
 | 
			
		||||
  <!--<Target Name="CoreCompile" />-->
 | 
			
		||||
  <Target Name="BeforeBuild">
 | 
			
		||||
  </Target>
 | 
			
		||||
  <Target Name="AfterBuild">
 | 
			
		||||
  </Target>
 | 
			
		||||
</Project>
 | 
			
		||||
		Reference in New Issue
	
	Block a user