Python爬虫爬企查查数据
因为制作B2b网站需要,需要入库企业信息数据。所以目光锁定企查查数据,废话不多说,开干!
#-*- coding-8 -*-
import requests
import lxml
import sys
from bs4 import BeautifulSoup
import xlwt
import time
import urllib
def craw(url,key_word,x):
User_Agent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0'
# if x == 0:
# re = 'http://www.qichacha.com/search?key='+key_word
# else:
# re = 'https://www.qichacha.com/search?key={}#p:{}&'.format(key_word,x-1)
re = r'https://www.qichacha.com/search?key='+key_word
headers = {
'Host':'www.qichacha.com',
'Connection': 'keep-alive',
'Accept':r'text/html, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent':r'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
'Referer': re,
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.9',
'Cookie':r'xxxxxxxxx这里换成你的cookiexxxxxxxx这里换成你的cookiexxxxxxxxx这里换成你的cookiexxxxxxx',
}
try:
response = requests.get(url,headers = headers)
if response.status_code != 200:
response.encoding = 'utf-8'
print(response.status_code)
print('ERROR')
soup = BeautifulSoup(response.text,'lxml')
except Exception:
print('请求都不让,这企查查是想逆天吗???')
try:
com_all_info = soup.find_all(class_='m_srchList')[0].tbody
com_all_info_array = com_all_info.select('tr')
print('开始爬取数据,请勿打开excel')
for i in range(0,len(com_all_info_array)):
# try:
temp_g_name = com_all_info_array[i].select('td')[2].select('.ma_h1')[0].text #获取公司名
temp_g_tag = com_all_info_array[i].select('td')[2].select('.search-tags')[0].text #获取公司标签
temp_r_name = com_all_info_array[i].select('td')[2].select('p')[0].a.text #获取法人名
temp_g_money = com_all_info_array[i].select('td')[2].select('p')[0].select('span')[0].text.strip('注册资本:') #获取注册资本
temp_g_date = com_all_info_array[i].select('td')[2].select('p')[0].select('span')[1].text.strip('成立日期:') #获取公司注册时间
temp_r_email = com_all_info_array[i].select('td')[2].select('p')[1].text.split('\n')[1].strip().strip('邮箱:') #获取法人Email
temp_r_phone = com_all_info_array[i].select('td')[2].select('p')[1].select('.m-l')[0].text.strip('电话:') #获取法人手机号
temp_g_addr = com_all_info_array[i].select('td')[2].select('p')[2].text.strip().strip('地址:') #获取公司地址
temp_g_state = com_all_info_array[i].select('td')[3].select('.nstatus.text-success-lt.m-l-xs')[0].text.strip() #获取公司状态
g_name_list.append(temp_g_name)
g_tag_list.append(temp_g_tag)
r_name_list.append(temp_r_name)
g_money_list.append(temp_g_money)
g_date_list.append(temp_g_date)
r_email_list.append(temp_r_email)
r_phone_list.append(temp_r_phone)
g_addr_list.append(temp_g_addr)
g_state_list.append(temp_g_state)
# except Exception:
# print('错误!')
except Exception:
print('好像被拒绝访问了呢...请稍后再试叭...')
if __name__ == '__main__':
global g_name_list
global g_tag_list
global r_name_list
global g_money_list
global g_date_list
global r_email_list
global r_phone_list
global g_addr_list
global g_state_list
g_name_list=[]
g_tag_list=[]
r_name_list=[]
g_money_list=[]
g_date_list=[]
r_email_list=[]
r_phone_list=[]
g_addr_list=[]
g_state_list=[]
key_word = input('请输入您想搜索的关键词:')
num = int(input('请输入您想检索的次数:'))+1
sleep_time = int(input('请输入每次检索延时的秒数:'))
key_word = urllib.parse.quote(key_word)
print('正在搜索,请稍后')
for x in range(1,num):
url = r'https://www.qichacha.com/search_index?key={}&ajaxflag=1&p={}&'.format(key_word,x)
s1 = craw(url,key_word,x)
time.sleep(sleep_time)
workbook = xlwt.Workbook()
#创建sheet对象,新建sheet
sheet1 = workbook.add_sheet('企查查数据', cell_overwrite_ok=True)
#---设置excel样式---
#初始化样式
style = xlwt.XFStyle()
#创建字体样式
font = xlwt.Font()
font.name = '仿宋'
# font.bold = True #加粗
#设置字体
style.font = font
#使用样式写入数据
print('正在存储数据,请勿打开excel')
#向sheet中写入数据
name_list = ['公司名字','公司标签','法定法人','注册资本','成立日期','法人邮箱','法人电话','公司地址','公司状态']
for cc in range(0,len(name_list)):
sheet1.write(0,cc,name_list[cc],style)
for i in range(0,len(g_name_list)):
print(g_name_list[i])
sheet1.write(i+1,0,g_name_list[i],style)#公司名字
sheet1.write(i+1,1,g_tag_list[i],style)#公司标签
sheet1.write(i+1,2,r_name_list[i],style)#法定法人
sheet1.write(i+1,3,g_money_list[i],style)#注册资本
sheet1.write(i+1,4,g_date_list[i],style)#成立日期
sheet1.write(i+1,5,r_email_list[i],style)#法人邮箱
sheet1.write(i+1,6,r_phone_list[i],style)#法人电话
sheet1.write(i+1,7,g_addr_list[i],style)#公司地址
sheet1.write(i+1,8,g_state_list[i],style)#公司状态
#保存excel文件,有同名的直接覆盖
workbook.save(r"D:\wyy-qcc-"+time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) +".xls")
print('保存完毕~')
Python爬虫爬企查查数据的更多相关文章
- python爬虫爬取天气数据并图形化显示
前言 使用python进行网页数据的爬取现在已经很常见了,而对天气数据的爬取更是入门级的新手操作,很多人学习爬虫都从天气开始,本文便是介绍了从中国天气网爬取天气数据,能够实现输入想要查询的城市,返回该 ...
- python爬虫——爬取网页数据和解析数据
1.网络爬虫的基本概念 网络爬虫(又称网络蜘蛛,机器人),就是模拟客户端发送网络请求,接收请求响应,一种按照一定的规则,自动地抓取互联网信息的程序.只要浏览器能够做的事情,原则上,爬虫都能够做到. 2 ...
- 使用python爬虫爬取股票数据
前言: 编写一个爬虫脚本,用于爬取东方财富网的上海股票代码,并通过爬取百度股票的单个股票数据,将所有上海股票数据爬取下来并保存到本地文件中 系统环境: 64位win10系统,64位python3.6, ...
- python爬虫----爬取阿里数据银行websocket接口
业务需求:爬取阿里品牌数据银行的自定义模块==>>>人群透视==>>>查看报告==>>数据 发现:数据通过websocket接口传递,此类型接口的详细理 ...
- java调用Linux执行Python爬虫,并将数据存储到elasticsearch--(环境脚本搭建)
java调用Linux执行Python爬虫,并将数据存储到elasticsearch中 一.以下博客代码使用的开发工具及环境如下: 1.idea: 2.jdk:1.8 3.elasticsearch: ...
- 用Python爬虫爬取广州大学教务系统的成绩(内网访问)
用Python爬虫爬取广州大学教务系统的成绩(内网访问) 在进行爬取前,首先要了解: 1.什么是CSS选择器? 每一条css样式定义由两部分组成,形式如下: [code] 选择器{样式} [/code ...
- 使用Python爬虫爬取网络美女图片
代码地址如下:http://www.demodashi.com/demo/13500.html 准备工作 安装python3.6 略 安装requests库(用于请求静态页面) pip install ...
- Python爬虫|爬取喜马拉雅音频
"GOOD Python爬虫|爬取喜马拉雅音频 喜马拉雅是知名的专业的音频分享平台,用户规模突破4.8亿,汇集了有声小说,有声读物,儿童睡前故事,相声小品等数亿条音频,成为国内发展最快.规模 ...
- Python爬虫爬取全书网小说,程序源码+程序详细分析
Python爬虫爬取全书网小说教程 第一步:打开谷歌浏览器,搜索全书网,然后再点击你想下载的小说,进入图一页面后点击F12选择Network,如果没有内容按F5刷新一下 点击Network之后出现如下 ...
随机推荐
- 【视频开发】ONVIF、RTSP/RTP、FFMPEG的开发实录
ONVIF.RTSP/RTP.FFMPEG的开发实录 前言 本文从零基础一步步实现ONVIF协议.RTSP/RTP协议获取IPC实时视频流.FFMPEG解码.开发环境为WIN7 32位 + VS201 ...
- TCP/IP学习笔记1--概述,分组交换协议
1.TCP/IP 互联网是由许多独立发展的网络通信技术融合而成的,能够使它们不断融合并实现统一的正式TCP/IP技术,TCP/IP使通信协议的统称. TCP/IP协议模型(Transmission C ...
- 处理html换行问题
String.prototype.replaceAll = function (FindText, RepText) { regExp = new RegExp(FindText, "g&q ...
- 打开iBatis显示运行sql语句
将ibatis log4j运行级别调到DEBUG可以在控制台打印出ibatis运行的sql语句,方便调试: log4j.logger.com.ibatis=DEBUG log4j.logger.com ...
- Sqlserver (转载)事物与锁
1 概述 本篇文章简要对事物与锁的分析比较详细,因此就转载了. 2 具体内容 并发可以定义为多个进程同时访问或修改共享数据的能力.处于活动状态而互不干涉的并发用户进程的数量越多,数据库系统的并 ...
- JSON学习(二)
首先,定义一个实体类Person: import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; public ...
- springboot+mybatis实现数据库的读写分离
介绍 随着业务的发展,除了拆分业务模块外,数据库的读写分离也是常见的优化手段.方案使用了AbstractRoutingDataSource和mybatis plugin来动态的选择数据源选择这个方案的 ...
- 打家劫舍II
题目描述(LeetCode) 你是一个专业的小偷,计划偷窃沿街的房屋,每间房内都藏有一定的现金.这个地方所有的房屋都围成一圈,这意味着第一个房屋和最后一个房屋是紧挨着的.同时,相邻的房屋装有相互连通的 ...
- C# 获取特殊日期
//1.当前时间DateTime dt = DateTime.Now; //2.本周周一DateTime startWeek = dt.AddDays(1 - Convert.ToInt32(dt.D ...
- 如何配置这个maven仓库的源http://mvnrepository.com/repos
http://mvnrepository.com/repos 主要是ID .mirrorof.name 怎么配置,这个网站上有spring5.0的,别的仓库没有,我需要这个源. 原文地址:https: ...