Python ---- requests(爬虫)教程二----练习
练习:爬取一起学的源代码
答案(可自行更改):
import requests
if __name__ == "__main__":
url = "https://livecdn.17zuoye.cn/zylive/student/2.32.1/pc.html"
response = requests.get(url = url)
page_text = response.text
print(page_text)
with open('yiqixue.html', 'w', encoding='gbk') as fp:
fp.write(page_text)
print('成功爬取')
本文提供了一个使用Python的requests库进行网页爬取的实战案例,目标是一起学网站的源代码。通过简单的代码实现,展示了如何获取指定URL的内容,并将其保存为本地HTML文件。


被折叠的 条评论
为什么被折叠?



