前言

本文主要采取cookie登录的方式爬取企查查网站的公司的基本信息,后期会继续发布关于爬取企查查网站上的公司的裁判文书信息。链接为:企查查  本文中若存在不详细的地方欢迎各位大神网友提问,若有错误的地方,希望大家指正。谢谢!! ? ?

粗略分析

1.进入企查查网站首页,在输入框输入某公司的全名(现在用名或曾用名),点击搜索可以查询结果列表页。如下图所示:

同时可以看到查询时的网页链接为https://www.qichacha.com/search?key=“公司名”。若给出公司全名,刚列表页中第一个即为我们要爬取的公司。写程序时可直接用xpath提取第一项的链接。
2.点击进入要爬取的公司可以看到该公司的具体信息。点击“基本信息”项,可以看到网页的链接变为https://www.qichacha.com/firm_此处为一串数字.html#base。可提取信息如下:

程序分析

1.items

class QichachaItem(scrapy.Item):name = scrapy.Field()phone = scrapy.Field()website = scrapy.Field()email = scrapy.Field()address = scrapy.Field()registered_capital = scrapy.Field()       #注册资本contributed_capital = scrapy.Field()      #实缴资本status = scrapy.Field()                   #经营状态establishment = scrapy.Field()            #成立日期social_code = scrapy.Field()              #统一社会信用代码taxpayer_num = scrapy.Field()             #纳税人识别号registrate_num = scrapy.Field()           #注册号organization_code = scrapy.Field()        #组织机构代码company_type = scrapy.Field()             #公司类型industry_involed = scrapy.Field()         #所属行业approval_date = scrapy.Field()            #核准日期registration_authority = scrapy.Field()   #登记机关area = scrapy.Field()                     #所属地区english_name = scrapy.Field()             #英文名used_name = scrapy.Field()                #曾用名insured_num = scrapy.Field()              #参保人数staff_size = scrapy.Field()               #人员规模operate_period = scrapy.Field()           #营业期限business_scope = scrapy.Field()           #经营范围

2.spiders

码前分析

因为是查询一系列公司的信息,所以在程序中我把公司名称写入了txt文件,遍历查询,并通过cookie登录。最后写入MySQL数据库

代码
class QccSpider(scrapy.Spider):name = 'qcc'allowed_domains = ['qichacha.com']start_urls = ['https://www.qichacha.com/search?key=']x = 1def start_requests(self):#查询公司f = open('G://task/qichacha/qichacha/spiders/company_list.txt','r',encoding='utf-8')for link in f:company = urllib.parse.quote(link).replace('\n','')url = self.start_urls[0] + companyyield scrapy.Request(url,cookies=COOKIES,callback=self.parse)def parse(self,response):#提取列表中第一个公司,进入该页link = response.xpath('//tbody/tr[1]/td[2]/a/@href').extract_first()detail_link = response.urljoin(link) + '#base'#print(detail_link)yield scrapy.Request(detail_link,cookies=COOKIES,callback=self.page_parse)def page_parse(self,response):item = QichachaItem()#公司名name = response.xpath('//div[@class="content"]/div[1]/h1/text()').extract_first()item['name'] = name.strip().replace('\n','') if name else '暂无公司名信息'#电话phone = response.xpath('//div[@class="content"]/div[2]/span[1]/span[2]/span/text()').extract_first()item['phone'] = phone.strip().replace('\n','') if phone else '暂无电话信息'#官网website = response.xpath('//div[@class="content"]/div[2]/span[3]/a/@href').extract_first()item['website'] = website.strip().replace('\n','') if website else '暂无网站信息'#邮箱email = response.xpath('//div[@class="content"]/div[3]/span[1]/span[2]/a/text()').extract_first()if email:item['email'] = emailelse:email2 = response.xpath('//div[@class="content"]/div[3]/span[1]/span[2]/text()').extract_first()item['email'] = email2.strip().replace('\n','')#地址address = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[10]/td[2]/text()').extract_first()item['address'] = address.strip().replace('\n','') if address else '暂无地址信息'#注册资本registered_capital = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[1]/td[2]/text()').extract_first()item['registered_capital'] = registered_capital.replace('\n','').strip() if registered_capital else '暂无注册资本'#实缴资本contributed_capital = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[1]/td[4]/text()').extract_first()if contributed_capital:item['contributed_capital'] = contributed_capital.replace('\n','').strip()else:item['contributed_capital'] = '暂无实缴资本'#经营状态status = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[2]/td[2]/text()').extract_first()if status:item['status'] = status.replace('\n','').strip()else:item['status'] = '暂无经营状态信息'#成立日期establishment = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[2]/td[4]/text()').extract_first()if establishment:item['establishment'] = establishment.replace('\n','').strip()else:item['establishment'] = '暂无成立日期信息'#统一社会信用代码social_code = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[3]/td[2]/text()').extract_first()if social_code:item['social_code'] = social_code.replace('\n','').strip()else:item['social_code'] = '暂无统一社会信息代码信息'#纳税人识别号taxpayer_num = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[3]/td[4]/text()').extract_first()if taxpayer_num:item['taxpayer_num'] = taxpayer_num.replace('\n','').strip()else:item['taxpayer_num'] = '暂无纳税人识别号信息'#注册号registrate_num = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[4]/td[2]/text()').extract_first()if registrate_num:item['registrate_num'] = registrate_num.replace('\n','').strip()else:item['registrate_num'] = '暂无注册号信息'#组织机构代码organization_code = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[4]/td[4]/text()').extract_first()if organization_code:item['organization_code'] = organization_code.replace('\n','').strip()else:item['organization_code'] = '暂无组织机构代码信息'#公司类型company_type = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[5]/td[2]/text()').extract_first()if company_type:item['company_type'] = company_type.replace('\n','').strip()else:item['company_type'] = '暂无公司类型信息'#所属行业industry_involed = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[5]/td[4]/text()').extract_first()if industry_involed:item['industry_involed'] = industry_involed.replace('\n','').strip()else:item['industry_involed'] = '暂无所属行业信息'#核准日期approval_date = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[6]/td[2]/text()').extract_first()if approval_date:item['approval_date'] = approval_date.replace('\n','').strip()else:item['approval_date'] = '暂无核准日期信息'#登记机关registration_authority = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[6]/td[4]/text()').extract_first()if registration_authority:item['registration_authority'] = registration_authority.replace('\n','').strip()else:item['registration_authority'] = '暂无登记机关信息'#所属地区area = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[7]/td[2]/text()').extract_first()if area:item['area'] = area.replace('\n','').strip()else:item['area'] = '暂无所属地区信息'#英文名english_name = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[7]/td[4]/text()').extract_first()if english_name:item['english_name'] = english_name.replace('\n','').strip()else:item['english_name'] = '暂无英文名信息'#曾用名used = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[8]/td[2]')used_name = used.xpath('string(.)').extract_first()if used_name:item['used_name'] = used_name.replace('\n','').strip().replace('\xa0','')else:item['used_name'] = '暂无曾用名'#参保人数insured_num = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[8]/td[4]/text()').extract_first()if insured_num:item['insured_num'] = insured_num.replace('\n','').strip()else:item['insured_num'] = '暂无参保人数信息'#人员规模staff_size = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[9]/td[2]/text()').extract_first()if staff_size:item['staff_size'] = staff_size.replace('\n','').strip()else:item['staff_size'] = '暂无人员规模信息'#营业期限operate_period = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[9]/td[4]/text()').extract_first()if operate_period:item['operate_period'] = operate_period.replace('\n','').strip()else:item['operate_period'] = '暂无营业期限信息'#经营范围business_scope = response.xpath('//section[@id="Cominfo"]/table[@class="ntable"][2]/tr[11]/td[2]/text()').extract_first()if business_scope:item['business_scope'] = business_scope.replace('\n','').strip()else:item['business_scope'] = '暂无经营范围信息'yield item
  1. 其它
    本程序将爬取信息写入了数据库,此处同settings一样,不再列出。

再次声明

若有错误及改进之处,望大家批评指正。

西山小菜鸟之Scrapy学习笔记---爬取企查查网站公司基本信息相关推荐

  1. 西山小菜鸟之Scrapy学习笔记---爬取企查查网公司的裁判文书信息

    前言 本文接着上文,爬取企查查的公司裁判文书信息.企查查  本文中若存在不详细的地方欢迎各位大神网友提问,若有错误的地方,希望大家指正.谢谢!! ? ? 粗略分析 点击进入要查询的公司可以进入该公司的 ...

  2. Python爬虫:输入公司名称,爬取企查查网站中的公司信息

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理. 以下文章来源于Python爬虫数据分析挖掘 ,作者:李运辰 根据输入的公司名称来爬取企查查网 ...

  3. Python3爬取企查查网站的企业年表并存入MySQL

    Python3爬取企查查网站的企业年表并存入MySQL 本篇博客的主要内容:爬取企查查网站的企业年报数据,存到mysql中,为了方便记录,分成两个模块来写: 第一个模块是爬取数据+解析数据,并将数据存 ...

  4. Scrapy学习笔记 爬取w3school

    本文学习自:https://www.urlteam.org/2016/06/scrapy-%E5%85%A5%E9%97%A8%E9%A1%B9%E7%9B%AE-%E7%88%AC%E8%99%AB ...

  5. Python爬虫学习笔记 -- 爬取糗事百科

    Python爬虫学习笔记 -- 爬取糗事百科 代码存放地址: https://github.com/xyls2011/python/tree/master/qiushibaike 爬取网址:https ...

  6. 读书笔记(十)——python简单爬取企查查网企业信息,并以excel格式存储

    2019独角兽企业重金招聘Python工程师标准>>> 今天这个小爬虫是应朋友,帮忙写的一个简单的爬虫,目的是爬取企查查这个网站的企业信息. 编程最终要的就是搭建编程环境,这里我们的 ...

  7. python 爬取企业注册信息_读书笔记(十)——python简单爬取企查查网企业信息,并以excel格式存储...

    今天这个小爬虫是应朋友,帮忙写的一个简单的爬虫,目的是爬取企查查这个网站的企业信息. 编程最终要的就是搭建编程环境,这里我们的编程环境是: python3.6 BeautifulSoup模块 lxml ...

  8. java企查查爬_爬取企查查热搜

    由于是第一次写作可能代码风格比较丑而且语言表达不好,各位看官请见谅. 下面进入正题临时接到一个任务爬取企查查的网络热词,并且要定时更新. 下面是要爬取的网页内容. image 之前有写过这个页面的解析 ...

  9. python爬取去哪网数据_用户观点:企查查数据爬取技术与Python 爬取企查查数据...

    主体数据来源是全国工商信用网但是每个省的工商系统都不同,要针对每个省的工商系统单独写爬虫每个省的验证码也不同,也要单独做.企查查的原理不是主动爬去数据,而是有人查询该企业时,如果自己的数据库没有该企业 ...

最新文章

  1. 差点被人类消灭的疾病,科学家说是苏联让它重新肆虐全球?
  2. 【Android 应用开发】Google 官方 EasyPermissions 权限申请库 ( 权限申请原理对话框操作回调接口 | 永久拒绝权限后引导设用户置权限 )
  3. C语言内存泄露很严重该怎么办?这几招告诉你
  4. 企业传播可以考虑放弃公众号了
  5. 批量修改历史commit的用户名user.name邮箱user.email
  6. 机器学习之kNN算法(纯python实现)
  7. itex将html转成pdf加水印,itext操作PDF文件添加水印
  8. 有人抄袭微信红包和表情被罚了40万!这下“吹牛”可能牛不起来了
  9. JS实现new关键字的功能
  10. C语言中各数据类型和他们对应的最大值和最小值的常量
  11. const 成员函数
  12. 智能家居系统c语言源代码,智能家居软件设计(附源程序).doc
  13. linux shell文件转码命令:iconv
  14. 群控系统linux脚本,万能安卓群控脚本助手(安卓群控软件)V1.1 最新版
  15. 《深度学习》花书-读书笔记汇总贴(汇总19/19)
  16. C#添加 / 创建本地数据库连接
  17. chrome内核 用h5调用高拍仪(摄像图)实现拍证件照
  18. 【记录】使用在线KMS激活Office系列
  19. poj3046 Ant Counting
  20. tp控制器进阶页面跳转重定向、

热门文章

  1. NC 开发环境因电脑高分辨率导致系统文字、图标变小等。
  2. ASEMI整流二极管10A10参数,10A10压降,10A10作用
  3. 一文搞懂什么是GPA
  4. 35+了,发奋读书改变命运,还有机会吗?
  5. [技术干货] zabbix docker安装详细教程
  6. MySQL数据库入门(三)--- 查询、权限、join语法、外键、备份
  7. 抢红包 作者 陈越单位 浙江大学
  8. Leetcode力扣 VS Code插件——面向新手
  9. 极路由设置虚拟服务器,HiWiFi极路由手机设置教程
  10. [java] JDBC数据库编程