• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

selenium操作进入页面截图+scrapy爬虫

武飞扬头像
mnwl12_0
帮助1

  1.  
    #导入相关包
  2.  
    from selenium import webdriver
  3.  
    from time import sleep
  4.  
    #定义类
  5.  
    class FirstSelenium(object):
  6.  
    def __int__(self):
  7.  
    self.driver=None
  8.  
    #初始化浏览器对象
  9.  
    def get_driver(self):
  10.  
    #指定路径
  11.  
    driver_path=r'C:\Program Files\chromedriver.exe' #r'.\chromedriver.exe'
  12.  
    #初始化对象
  13.  
    self.driver=webdriver.Chrome(executable_path=driver_path)
  14.  
    #sleep(3)
  15.  
    #self.driver.close()
  16.  
    #设置窗口最大化
  17.  
    self.driver.maximize_window()
  18.  
    #隐形等待时间
  19.  
    self.driver.implicitly_wait(10)
  20.  
     
  21.  
     
  22.  
     
  23.  
    def auto_opera(self):
  24.  
    self.driver.get('https://ksgmis.kingstartech.com/newmis/')
  25.  
    sleep(1)
  26.  
    self.driver.find_element_by_id('username').send_keys('C0323')
  27.  
    sleep(1)
  28.  
    self.driver.find_element_by_id('password').send_keys('Kingstar123')
  29.  
    sleep(1)
  30.  
    self.driver.find_element_by_xpath('//*[@id="loginForm"]/div[2]/div[6]/input').click()
  31.  
    #self.driver.find_element_by_id('button').click()
  32.  
    sleep(2)
  33.  
    self.driver.find_element_by_xpath('/html/body/div[11]/div[2]/div/div/div/span/div/div/div/div[1]/div[2]/div[1]/div').click()
  34.  
    sleep(2)
  35.  
    windows=self.driver.window_handles
  36.  
    self.driver.switch_to_window(windows[-1])
  37.  
    self.driver.get_screenshot_as_file('日志填写.png')
  38.  
    sleep(10)
  39.  
     
  40.  
    if __name__=='__main__':
  41.  
    f=FirstSelenium()
  42.  
    f.get_driver()
  43.  
    f.auto_opera()
学新通

学新通

学新通

学新通

学新通

----------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------

学新通

学新通 

学新通

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfhkgi
系列文章
更多 icon
同类精品
更多 icon
继续加载