從企查查爬取企業信息,如果沒有登錄直接檢索,郵箱、電話都被隱藏了
點擊詳情,部分信息同樣會被隱藏
畢竟只是打工的,沒錢不能任性!
想要查看更完整的企業信息,只有登錄了。
但登錄需要滑塊驗證,有時可能還會有圖片驗證碼
但我干不過他們,老大不提供資金支持,那就只能另辟蹊徑了。
突然看到右下角有三小只,不禁有點想法了
是不是可以通過授權的形式進行登錄呢,那就開始吧
那就拿三小只試試:
首先通過微博登錄,將該綁定的綁定,該授權的授權,避免登錄后讓驗證
(微博授權 + 手機號綁定 + 竟然還讓關注了公眾號)
賬號准備完畢,上代碼
from selenium import webdriver import time import xlwt import sys import imp imp.reload(sys) # 偽裝成瀏覽器,防止被識破 option = webdriver.ChromeOptions() option.add_argument( '--user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36"') driver = webdriver.Chrome(chrome_options=option) # 打開登錄頁面 driver.get('https://www.qichacha.com/user_login') # 單擊用戶名密碼登錄的標簽 tag = driver.find_element_by_xpath('//*[@id="normalLogin"]') tag.click() tag = driver.find_element_by_xpath('//*[@class="btn-weibo m-l-xs"]') tag.click() # 將用戶名、密碼注入 driver.find_element_by_id('userId').send_keys('微博賬號') driver.find_element_by_id('passwd').send_keys('微博密碼') time.sleep(3) # 休眠,人工完成驗證步驟,等待程序單擊“登錄” # 單擊登錄按鈕 btn = driver.find_element_by_xpath('//*[@id="outer"]/div/div[2]/form/div/div[2]/div/p/a[1]') btn.click() time.sleep(10) # inc_list = ['阿里巴巴', '騰訊', '今日頭條', '滴滴', '美團'] # inc_len = len(inc_list) driver.find_element_by_id('searchkey').send_keys("騰訊") # 單擊搜索按鈕 srh_btn = driver.find_element_by_xpath('//*[@id="indexSearchForm"]/div/span/input') srh_btn.click() # 獲取首個企業文本 inc_full = driver.find_element_by_xpath('//*[@id="search-result"]/tr[1]/td[3]/a').text print(inc_full) money = driver.find_element_by_xpath('//*[@id="search-result"]/tr[1]/td[3]/p[1]/span[1]').text print(money) date = driver.find_element_by_xpath('//*[@id="search-result"]/tr[1]/td[3]/p[1]/span[2]').text print(date) mail_phone = driver.find_element_by_xpath('//*[@id="search-result"]/tr[1]/td[3]/p[2]').text print(mail_phone) addr = driver.find_element_by_xpath('//*[@id="search-result"]/tr[1]/td[3]/p[3]').text print(addr) try: stock_or_others = driver.find_element_by_xpath('//*[@id="search-result"]/tr[1]/td[3]/p[4]').text print(stock_or_others) except: pass # 獲取網頁地址,進入 inner = driver.find_element_by_xpath('//*[@id="search-result"]/tr[1]/td[3]/a').get_attribute("href") driver.get(inner) # 單擊進入后 官網 通過href屬性獲得: inc_web = driver.find_element_by_xpath( '//*[@id="company-top"]/div[2]/div[2]/div[3]/div[1]/span[3]/a').get_attribute("href") print("官網:" + inc_web) print(' ') driver.close()
信息獲取完整,ok