encoding: utf-8
from bs4 import BeautifulSoup
import requests
from urllib.request import urlopen
import re
import json
def visit(url):
headers = {
“User-Agent”: “Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3)”,
“accept”: “application/json, text/javascript, /; q=0.01”,
“accept-encoding”: “gzip, deflate, br”,
“accept-language”: “zh-CN,zh;q=0.9”,
“content-type”: “application/x-www-form-urlencoded; charset=UTF-8”,
“cookie”: “”, – 填自己的
“referer”: “”,
“sec-fetch-dest”: “document”,
“sec-fetch-mode”: “navigate”,
“sec-fetch-site”: “same-origin”,
}
res = requests.get(url,headers=headers)
bsObj = BeautifulSoup(res.text, “html.parser”)
return bsObj
def visit_homepage(url):
bsObj = visit(url)
content = bsObj.find(‘div’, class_=“content”)
content_list = content.select(“p”)
category = []
for i in range(4,len(content_list)):
try:
urls = content_list[i].a[‘href’]
name = content_list[i].get_text(“|”).split(“|”)[0].replace(’ ‘,’‘).replace(’\xa0’,‘’)
category.append([name,urls])
except:
pass
print(category)
return category
def download_pdf(conf,path):
category_name = conf[0]
category_url = conf[1]
bsObj = visit(category_url)
res = re.search(r’(.)token:(.?),',str(bsObj) ,re.M|re.I)
token = res.group(2).replace(‘"’,‘’).replace(’ ‘,’')
arts = re.findall(r’(.)li data-docinfo=(.?)}',str(bsObj) ,re.M|re.I)
for art in arts:
art_str = “{”+str(art).split(‘{’)[1].replace(“')”,“}”)
art_dic = json.loads(art_str)
id = art_dic[‘id’]
name = art_dic[‘name’]
download_url = “https://api.z.itpub.net/download/file?st-usertoken=%s&id=%s”%(token,str(id))
print(download_url)
data = urlopen(download_url).read()
with open(path+category_name+‘__’+name, ‘wb’) as f:
f.write(data)
print("finish download ")
if name == ‘main’:
homepage = “https://z.itpub.net/article/detail/5260C494873379BAA63BAB7C5CBD7A95”
path = “/Users/xxx/Downloads/DTCC/”
download
category = visit_homepage(homepage)
for i in category:
download_pdf(i,path)
程序下载
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Python工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Python开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以扫码获取!!!(备注Python)
适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!**
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以扫码获取!!!(备注Python)
![img](https://i-blog.csdnimg.cn/blog_migrate/32f8690ef3a06d92e3b72bb1d2a35096.jpeg)