本次项目呢其实也就是为了完成学校的实训项目,但我觉得好不错,所以分享出来。那就废话不多说,直接上。
第一步 爬虫:企查查电脑端,公司的网址信息
企查查电脑端需要用户登录后才能爬取信息,因此事先需要注册账号,使用selenium方法模拟登录
import time
import pandas as pd
from selenium import webdriver
from selenium.webdriver import ActionChains
a = []
def login(driver):
driver.delete_all_cookies()
url = "https://www.qcc.com/weblogin?back=%2F" #企查查登录网址
driver.get(url)
time.sleep(10)
# 点击密码登入
driver.find_element_by_xpath('/html/body/div[1]/div[3]/div/div[2]/div[1]/div[2]/a').click()
time.sleep(1)
# 输入账号密码
driver.find_element_by_xpath('/html/body/div[1]/div[3]/div/div[2]/div[3]/form/div[1]/input').send_keys(username)
driver.find_element_by_xpath('/html/body/div[1]/div[3]/div/div[2]/div[3]/form/div[2]/input').send_keys(password)
button = driver.find_element_by_xpath('/html/body/div[1]/div[3]/div/div[2]/div[3]/form/div[3]/div/div/div[1]/span')
#滑动滑块
ActionChains(driver).click_and_hold(button).perform()
ActionChains(driver).move_by_offset(xoffset=308, yoffset=0).perform()
ActionChains(driver).release().perform()
time.sleep(2)
driver.find_element_by_xpath('/html/body/div[1]/div[3]/div/div[2]/div[3]/form/div[4]/button/strong').click()# 点击登录
time.sleep(0.5)
模拟登录进入后,在搜索栏输入你想要爬取有关信息的公司,我这里输入的是游戏,
url_a = [#搜索搜索游戏
'https://www.qcc.com/web/search?key=%E6%B8%B8%E6%88%8F&p={}&filter=%7B%22rchain%22%3A%5B%7B%22pr%22%3A%22GD%22%7D%5D%7D',
'https://www.qcc.com/web/search?key=%E6%B8%B8%E6%88%8F&p={}&filter=%7B%22rchain%22%3A%5B%7B%22pr%22%3A%22BJ%22%7D%5D%7D',
'https://www.qcc.com/web/search?key=%E6%B8%B8%E6%88%8F&p={}&filter=%7