一、代码

由于企查查有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)
08-30 16:28