天眼查反爬的曲线救国道路-爬取红盾网企业信息(Python爬虫实战)

先在这里给出红盾网抓取企业信息代码,有时间再去研究如果对天眼查进行企业信息抓取,后续更新…

import requests
import time
from lxml import etree

headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3730.400 QQBrowser/10.5.3805.400'}

f=open("company_info.csv","a",encoding="utf-8")

def paser_detail(url):
    response = requests.get(url=url, headers=headers)
    time.sleep(1)
    items = etree.HTML(response.text)
    titles = items.xpath('//a[@class="name"]')
    for titl in titles:  # 地区
        title = titl.xpath('./text()')[0]
    lis = items.xpath('//*[@id="list-container"]/ul/li')
    for li in lis:
        mingcheng=li.xpath('./div/a/text()')[0]
        daima = li.xpath('./div/p[1]/a/span[1]/text()')[0]  # 代码
        person = li.xpath('./div/p[1]/a/span[2]/text()')[0]  # 法人
        address = li.xpath('./div/p[2]/a/span/text()')[0]  # 地址
        f.write(title+"\t"+mingcheng+"\t"+daima+"\t"+person+"\t"+address+"\n")
        data = [title, daima, person, address]
        collection = {
            '地区': title,
            '代码': daima,
            '法人': person,
            '地址': address
        }
        print(mingcheng,title, daima, person, address)
        
if __name__ == '__main__':
	for i in range(51,1000):#修改当前页
	    print("第"+str(i)+"页")
	    paser_detail("https://www.ubaike.cn/class_204/"+str(i)+".html")
  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值