Python爬虫实战小项目

Posted xuange1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python爬虫实战小项目相关的知识,希望对你有一定的参考价值。

爬取国家药品监督管理总局中基于中华人民共和国化妆品生产许可证相关数据

import requests
from fake_useragent import UserAgent
ua = UserAgent(use_cache_server=False,verify_ssl=False).random
headers = {
    ‘User-Agent‘:ua
}
url = ‘http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsList‘
pageNum = 3
for page in range(3,5):
    data = {
        ‘on‘: ‘true‘,
        ‘page‘: str(page),
        ‘pageSize‘: ‘15‘,
        ‘productName‘:‘‘,
        ‘conditionType‘: ‘1‘,
        ‘applyname‘:‘‘,
        ‘applysn‘:‘‘
    }
    json_text = requests.post(url=url,data=data,headers=headers).json()
    all_id_list = []
    for dict in json_text[‘list‘]:
        id = dict[‘ID‘]#用于二级页面数据获取
        #下列详情信息可以在二级页面中获取
        # name = dict[‘EPS_NAME‘]
        # product = dict[‘PRODUCT_SN‘]
        # man_name = dict[‘QF_MANAGER_NAME‘]
        # d1 = dict[‘XC_DATE‘]
        # d2 = dict[‘XK_DATE‘]
        all_id_list.append(id)
    #该url是一个ajax的post请求
    post_url = ‘http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsById‘
    for id in  all_id_list:
        post_data = {
            ‘id‘:id
        }
        response = requests.post(url=post_url,data=post_data,headers=headers)
        if response.headers[‘Content-Type‘] == ‘application/json;charset=UTF-8‘:
            #print(response.json())
            #进行json解析
            json_text = response.json()
            print(json_text[‘businessPerson‘])

  

以上是关于Python爬虫实战小项目的主要内容,如果未能解决你的问题,请参考以下文章

Python爬虫项目实战-爬取猫眼电影

Python爬虫实战为何如此痴迷Python?还不是因为爱看小姐姐图

小知识点爬虫训练场项目,Python Flask 模板更新,每次都要重新服务

Python爬虫编程思想(61): 项目实战:抓取租房信息

Python3爬虫实战:实战源码+博客讲解

python爬虫实战——5分钟做个图片自动下载器