自己写的爬虫小案例

网址:aHR0cDovL2pzc2NqZ3B0Lmp4d3JkLmdvdi5jbi8/dXJsPS92aWV3L3dvcmtpbmdVbml0L3dvcmtpbmdVbml0Lmh0bWw=

这串代码能够爬取勘察单位企业的详细信息。

python 复制代码
import requests
import time
import csv
f = open('勘察单位公司信息.csv','w',encoding='utf-8',newline='')
csv_writer = csv.DictWriter(f,fieldnames=[
    '公司名称',
    '涉及领域',
    '所属省市',
    '注册资本(万元)',
    '成立日期',
    '发证机关',
    '统一社会信用码',
    '经营范围',
    '单位网址',
    '法人',
    '主营业务',
    '注册地址',
    '证书网址',
    
])
csv_writer.writeheader()
cookies = {
    'JSESSIONID': 'BD8F06872E4D854606108A0F4AF55D79',
}
def get_response(id):
    info_url = f'http://jsscjgpt.jxwrd.gov.cn/api/employer/findByEmployer?unitId={id}'
    result = requests.get(url=info_url,headers=headers).json()
    return result
headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Type': 'application/json',
    # 'Cookie': 'JSESSIONID=BD8F06872E4D854606108A0F4AF55D79',
    'Origin': 'http://jsscjgpt.jxwrd.gov.cn',
    'Pragma': 'no-cache',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest',
}
for page in range(1,299):
    time.sleep(1)
    json_data = {
        'pageNum': page,
        'pageSize': 10,
        'query': '1',
        'unitName': '',
        'unitCode': '',
        'userName': '',
    }
    response = requests.post(
        'http://jsscjgpt.jxwrd.gov.cn/api/employer/findAll',
        cookies=cookies,
        headers=headers,
        json=json_data,
        verify=False,
    )
    json_response = response.json()
    for index in json_response['data']['list']:
        id = index['companyId']

        data = get_response(id)['data']
        dit = {
            '公司名称': data['name'],
            '涉及领域': data['categoryType'],
            '所属省市': data['address'],
            '注册资本(万元)': data['registeredMoney'],
            '成立日期': data['setUpYear'],
            '发证机关': data['certificateCompany'],
            '统一社会信用码': data['code'],
            '经营范围': data['businessRange'],
            '单位网址': data['companyUrl'],
            '法人': data['legalPerson'],
            '主营业务': data['mainBusiness'],
            '注册地址': data['registeredAddress'],
            '证书网址': data['companyCommitment'],
        }
        print(dit)
        csv_writer.writerow(dit)
相关推荐
985小水博一枚呀10 小时前
【对于Python爬虫的理解】数据挖掘、信息聚合、价格监控、新闻爬取等,附代码。
爬虫·python·深度学习·数据挖掘
大神薯条老师12 小时前
Python从入门到高手5.1节-Python简单数据类型
爬虫·python·深度学习·机器学习·数据分析
镜花照无眠16 小时前
Python爬虫使用实例-mdrama
开发语言·爬虫·python
小白学大数据1 天前
User-Agent在WebMagic爬虫中的重要性
开发语言·爬虫·http
大神薯条老师1 天前
Python从入门到高手4.3节-掌握跳转控制语句
后端·爬虫·python·深度学习·机器学习·数据分析
wdxylb2 天前
Pyhton爬虫使用Selenium实现浏览器自动化操作抓取网页
爬虫·selenium·测试工具
菜鸡中的奋斗鸡→挣扎鸡2 天前
初始爬虫11
开发语言·爬虫·python
凡人的AI工具箱2 天前
15分钟学 Python 第35天 :Python 爬虫入门(一)
开发语言·数据结构·人工智能·后端·爬虫·python
新缸中之脑2 天前
ScrapeGraphAI 大模型增强的网络爬虫
爬虫
易辰君2 天前
python爬虫 - 初识爬虫
开发语言·爬虫·python