最全Python爬取CSDN文章并制作成PDF,2024年最新Python面试超详细知识点

现在能在网上找到很多很多的学习资源,有免费的也有收费的,当我拿到1套比较全的学习资源之前,我并没着急去看第1节,我而是去审视这套资源是否值得学习,有时候也会去问一些学长的意见,如果可以之后,我会对这套学习资源做1个学习计划,我的学习计划主要包括规划图和学习进度表。

分享给大家这份我薅到的免费视频资料,质量还不错,大家可以跟着学习

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

‘margin-left’: ‘0.75in’,

‘encoding’: “UTF-8”,

‘custom-header’ : [

(‘Accept-Encoding’, ‘gzip’)

]

‘cookie’: [

(‘cookie-name1’, ‘cookie-value1’),

(‘cookie-name2’, ‘cookie-value2’),

],

‘no-outline’: None

}

pdfkit.from_url(‘http://google.com’, ‘out.pdf’, options=options)

完整代码


selenium_page.py

import re

import requests

def get_songid():

“”“获取音乐的songid”“”

url = ‘http://music.taihe.com/artist/2517’

response = requests.get(url=url)

html = response.text

sids = re.findall(r’href=“/song/(\d+)”', html)

return sids

def get_music_url(songid):

“”“获取下载链接”“”

api_url = f’http://musicapi.taihe.com/v1/restserver/ting?method=baidu.ting.song.playAAC&format=jsonp&songid={songid}&from=web’

response = requests.get(api_url.format(songid=songid))

data = response.json()

print(data)

try:

music_name = data[‘songinfo’][‘title’]

music_url = data[‘bitrate’][‘file_link’]

return music_name, music_url

except Exception as e:

print(e)

def download_music(music_name, music_url):

“”“下载音乐”“”

response = requests.get(music_url)

content = response.content

save_file(music_name+‘.mp3’, content)

def save_file(filename, content):

“”“保存音乐”“”

with open(file=filename, mode=“wb”) as f:

f.write(content)

if name == “main”:

for song_id in get_songid():

music_name, music_url = get_music_url(song_id)

download_music(music_name, music_url)

CSDN.py

-- coding=utf-8 --

import pdfkit

import parsel

import requests

html_template = “”"

{content}

“”"

headers = {

“User-Agent”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36”,

‘Host’: ‘blog.csdn.net’,

‘Referer’: ‘https://blog.csdn.net’,

}

def get_csdn_cookie():

response = requests.get(‘https://www.csdn.net/’, headers=headers)

return response.cookies

def get_html(url):

“”“获取索引页”“”

response = requests.get(url, headers=headers)

sel = parsel.Selector(response.text)

list_a = sel.css(‘.article-list a’)

for i in list_a[2:]:

article_index = i.css(‘a::attr(href)’).get()

yield article_index

def csdn(url: str, cookie=get_csdn_cookie()):

“”“下载 CSDN 文章html”“”

response = requests.get(url, headers=headers, cookies=cookie)

获取文章标题内容

sel = parsel.Selector(response.text)

print(response.text)

title = sel.css(‘.title-article::text’).get()

article = sel.css(‘article’).get()

return title, article

def html_to_pdf(filename_html, filename_pdf):

“”“HTML 2 PDF”“”

config = pdfkit.configuration(wkhtmltopdf=‘C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe’)

options = {

‘page-size’: ‘Letter’,

‘margin-top’: ‘0.75in’,

‘margin-right’: ‘0.75in’,

‘margin-bottom’: ‘0.75in’,

‘margin-left’: ‘0.75in’,

‘encoding’: “UTF-8”,

‘custom-header’: [

(‘Accept-Encoding’, ‘gzip’)

],

}

pdfkit.from_file(filename_html, filename_pdf, options=options, configuration=config)

if name == ‘main’:

title, article = csdn(‘https://blog.csdn.net/ZackSock/article/details/101645494’)

html = html_template.format(content=article)

最后

Python崛起并且风靡,因为优点多、应用领域广、被大牛们认可。学习 Python 门槛很低,但它的晋级路线很多,通过它你能进入机器学习、数据挖掘、大数据,CS等更加高级的领域。Python可以做网络应用,可以做科学计算,数据分析,可以做网络爬虫,可以做机器学习、自然语言处理、可以写游戏、可以做桌面应用…Python可以做的很多,你需要学好基础,再选择明确的方向。这里给大家分享一份全套的 Python 学习资料,给那些想学习 Python 的小伙伴们一点帮助!

👉Python所有方向的学习路线👈

Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。

👉Python必备开发工具👈

工欲善其事必先利其器。学习Python常用的开发软件都在这里了,给大家节省了很多时间。

👉Python全套学习视频👈

我们在看视频学习的时候,不能光动眼动脑不动手,比较科学的学习方法是在理解之后运用它们,这时候练手项目就很适合了。

👉实战案例👈

学python就与学数学一样,是不能只看书不做题的,直接看步骤和答案会让人误以为自己全都掌握了,但是碰到生题的时候还是会一筹莫展。

因此在学习python的过程中一定要记得多动手写代码,教程只需要看一两遍即可。

👉大厂面试真题👈

我们学习Python必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有阿里大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 29
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值