• 企查查 自动登录 获取数据


    直接上代码

    # encoding:utf-8
    # Author:"richie"
    
    import random
    import time
    from selenium.webdriver import ActionChains
    from selenium import webdriver
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    
    def get_driver():
        try:
            options = webdriver.ChromeOptions()   
            # 开启无界面模式    
            options.add_argument('--disable-gpu')  # 禁用gpu,解决一些莫名的问题    
            options.add_argument('blink-settings=imagesEnabled=false')  # 不加载图片, 提升速度    
            options.add_argument('--disable-infobars')  # 禁用浏览器正在被自动化程序控制的提示    
            options.add_argument('--start-maximized')    
            options.add_experimental_option("excludeSwitches", ["enable-automation"])    
            options.add_experimental_option('useAutomationExtension', False)    
            d = DesiredCapabilities.CHROME    
            d['goog:loggingPrefs'] = {'performance': 'ALL'}    
            driver = webdriver.Chrome(options=options, desired_capabilities=d)    
            driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {        
                "source": """        
                    Object.defineProperty(navigator, 'webdriver', {          get: () => undefined        })      """    
                    }
                )    
            driver.implicitly_wait(2)
            driver.maximize_window()    
            # driver.set_window_size(width=800, height=600)  
            return driver
        except BaseException as e:
            print(e)
            return None
    
    
    
    if __name__ == '__main__':
        driver = get_driver()
        driver.get("https://www.qichacha.com/user_login")
        driver.find_element_by_id("normalLogin").click()
        driver.find_element_by_id("nameNormal").send_keys("17320180454")
        driver.find_element_by_id("pwdNormal").send_keys("17320180454")
        time.sleep(2) 
        start = driver.find_element_by_xpath('//span[@class="nc_iconfont btn_slide"]')    
        action = ActionChains(driver)    
        action.click_and_hold(start)    
        action.drag_and_drop_by_offset(start, 308, 0).perform()    
        time.sleep(2)    
    
        driver.find_element_by_xpath('//*[@id="user_login_normal"]/button').click()
        time.sleep(5)
        corps = ['广州海洋勘探开发总公司', '广东车海洋环保科技有限公司', '广东粤新海洋工程装备股份有限公司', '广东省海洋工程职业技术学校(广东省海洋工程技工学校)']
    
        for data in corps:
                print(data)
                try:
                    # 输入公司名
                    driver.find_element_by_id('searchKey').send_keys(data)
                    time.sleep(1)
                    # 点击搜索
                    driver.find_element_by_class_name('btn-primary').click()
                    # driver.find_element_by_id('searchKey').clear()
                except Exception as e:
                    driver.find_element_by_id('searchkey').send_keys(data)
                    driver.find_element_by_class_name('index-searchbtn').click()
                driver.find_element_by_id('searchKey').clear()
                time.sleep(random.randint(1, 5))
               
    # encoding:utf-8
    # Author:"richie"

    import random
    import time
    from selenium.webdriver import ActionChains
    from selenium import webdriver
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

    def get_driver():
        try:
            options = webdriver.ChromeOptions()   
            # 开启无界面模式    
            options.add_argument('--disable-gpu')  # 禁用gpu,解决一些莫名的问题    
            options.add_argument('blink-settings=imagesEnabled=false')  # 不加载图片, 提升速度    
            options.add_argument('--disable-infobars')  # 禁用浏览器正在被自动化程序控制的提示    
            options.add_argument('--start-maximized')    
            options.add_experimental_option("excludeSwitches", ["enable-automation"])    
            options.add_experimental_option('useAutomationExtension'False)    
            d = DesiredCapabilities.CHROME    
            d['goog:loggingPrefs'] = {'performance''ALL'}    
            driver = webdriver.Chrome(options=optionsdesired_capabilities=d)    
            driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {        
                "source""""        
                    Object.defineProperty(navigator, 'webdriver', {          get: () => undefined        })      """    
                    }
                )    
            driver.implicitly_wait(2)
            driver.maximize_window()    
            # driver.set_window_size(width=800, height=600)  
            return driver
        except BaseException as e:
            print(e)
            return None



    if __name__ == '__main__':
        driver = get_driver()
        driver.get("https://www.qichacha.com/user_login")
        driver.find_element_by_id("normalLogin").click()
        driver.find_element_by_id("nameNormal").send_keys("17320180454")
        driver.find_element_by_id("pwdNormal").send_keys("17320180454")
        time.sleep(2
        start = driver.find_element_by_xpath('//span[@class="nc_iconfont btn_slide"]')    
        action = ActionChains(driver)    
        action.click_and_hold(start)    
        action.drag_and_drop_by_offset(start3080).perform()    
        time.sleep(2)    

        driver.find_element_by_xpath('//*[@id="user_login_normal"]/button').click()
        time.sleep(5)
        corps = ['广州海洋勘探开发总公司''广东车海洋环保科技有限公司''广东粤新海洋工程装备股份有限公司''广东省海洋工程职业技术学校(广东省海洋工程技工学校)']

        for data in corps:
                print(data)
                try:
                    # 输入公司名
                    driver.find_element_by_id('searchKey').send_keys(data)
                    time.sleep(1)
                    # 点击搜索
                    driver.find_element_by_class_name('btn-primary').click()
                    # driver.find_element_by_id('searchKey').clear()
                except Exception as e:
                    driver.find_element_by_id('searchkey').send_keys(data)
                    driver.find_element_by_class_name('index-searchbtn').click()
                driver.find_element_by_id('searchKey').clear()
                time.sleep(random.randint(15))
               
    作者:RichieWang
    出处:https://home.cnblogs.com/u/richiewlq/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,
    且在文章页面明显位置给出原文连接。
  • 相关阅读:
    oracle中job定时调用存储过程的实例
    oracle recyclebin详解(闪回删除的表)
    启动和禁用约束及删除违反约束的记录
    儒轩画的老鼠
    SQLServer2005重建索引
    [转]你真的了解 console 吗
    [转]C# 理解lock
    [转]大话 程序猿 眼里的 高并发
    莆田系医院名单
    .Net WEB 程序员需要掌握的技能
  • 原文地址:https://www.cnblogs.com/richiewlq/p/14939897.html
Copyright © 2020-2023  润新知