1. 程式人生 > 其它 >企查查 自動登入 獲取資料

企查查 自動登入 獲取資料

直接上程式碼

# 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"
importrandom importtime fromselenium.webdriverimportActionChains fromseleniumimportwebdriver fromselenium.webdriver.common.desired_capabilitiesimportDesiredCapabilities
defget_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) returndriver exceptBaseExceptionase: print(e) returnNone


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_iconfontbtn_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=['廣州海洋勘探開發總公司','廣東車海洋環保科技有限公司','廣東粵新海洋工程裝備股份有限公司','廣東省海洋工程職業技術學校(廣東省海洋工程技工學校)']
fordataincorps: 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() exceptExceptionase: 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))