一、代碼
由於企查查有ip查詢次數限制,多次查詢后會要求登入賬號,之后再出登入賬號后的查詢
import selenium.webdriver from selenium.webdriver.chrome.options import Options url = "https://www.qichacha.com/" options = Options() # 不能隱藏瀏覽器,會被檢測到,要求登入賬號 # options.add_argument('--headless') options.add_argument('--disable-gpu') options.add_argument('--user-agent="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36"') driver = selenium.webdriver.Chrome(options=options) # 等待時間 driver.implicitly_wait(5) driver.get(url) #獲取整個頁面 # print(driver.page_source) # 搜索框輸入 driver.find_element_by_xpath('//*[@id="searchkey"]').send_keys("汽車貿易服務有限公司") # 點擊查詢 driver.find_element_by_xpath('//*[@id="indexSearchForm"]/div/span/input').click() # 執行js獲取整個頁面 # html = driver.execute_script("return document.documentElement.outerHTML") # print(html) # 獲取數據 content=driver.find_element_by_xpath('//*[@id="search-result"]').text print(content)