企查查 自动登录 获取数据
直接上代码
# 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=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))
作者:RichieWang
出处:https://home.cnblogs.com/u/richiewlq/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,
且在文章页面明显位置给出原文连接。
出处:https://home.cnblogs.com/u/richiewlq/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,
且在文章页面明显位置给出原文连接。