(65)-- 爬取兄弟连老师信息

# 爬取兄弟连老师信息,先建一个teacher文件夹

from bs4 import BeautifulSoup
import requests
from urllib import request
import json

base_url = 'http://www.itxdl.cn/activity/teacher/teacher_lieibiao/'
response = requests.get(base_url)
response.encoding = 'gb2312'

html = response.text


html = BeautifulSoup(html,'lxml')


# 所有老师的div
teacher_list = html.select('div.php_jiangshi_liebiao')

teachers = []
with open('teacher.json','w',encoding='utf-8') as f:
    for teacher in teacher_list:
        name = teacher.select('h1')[0].text
        name = name.strip()
        industry = teacher.select('p')[0].text
        img = teacher.select('div.php_jiangshi_img img')[0]['src']

        fname = img.split('/')[-1]
        request.urlretrieve(img,'./teacher/' + fname)



        item = {
            'name' : name,
            'industry' : industry,
            'img' : img
        }
        teachers.append(item)




    f.write(json.dumps(teachers,indent=4,ensure_ascii=False))



# 还有一个自动生成的老师图片信息

兄弟连学python


Python学习交流、资源共享群:563626388 QQ


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值