用户:6BNT二免纯爱平板战士完全体曹小猹查看:0 回复:1 评论:0 创建时间:2023-09-24T23:51:44
【作品展示】

【作品介绍】
爬爬爬
【作品源代码】
import requests
from bs4 import BeautifulSoup
import easygui
import pyperclip
import importlib
tc = ["requests", "bs4",
"easygui", "pyperclip", "importlib"]
ml = []
for l in tc:
try:
importlib.import_module(l)
except ModuleNotFoundError:
ml.append(l)
if ml:
print("缺失的库:")
for li in ml:
print(li)
print('请补充相应的库')
else:
print("所有库均已安装(BeautifulSoup不予检查,请自行安装)")
try:
ex=0
while ex==0:
while ex==0:
ut = easygui.enterbox('输入要爬取的网站,喵https://"等也要打出来,获取源代码')
if ut:
easygui.msgbox(f"你的回答是:{ut}",)
break
else:
easygui.msgbox("你没有输入任何内容。")
ec=['是','否']
e = easygui.buttonbox("是否退出", choices=ec)
if e:
if e == '是':
ex=1
break
elif e == '否':
easygui.msgbox("继续")
if ex == 0:
url = ut
response = requests.get(url)
if response.status_code == 200:
print('请求成功')
print('源代码',response.text)
while ex==0:
cs = ["保存", "保存到剪切板", "重置","退出"]
c = easygui.buttonbox("请选择一个选项:", choices=cs)
if c:
easygui.msgbox(f"你选择了:{c}")
else:
easygui.msgbox("你没有选择任何选项。")
if c == '保存':
n = easygui.enterbox('输入想保存的名字(包含后缀.html)')
if n:
with open(n, 'w', encoding='utf-8') as html_file:
html_file.write(response.text)
easygui.msgbox(f'网页内容已保存为H喵L文件:,{n},请检查计算机')
elif c == '保存到剪切板':
copy = response.text
pyperclip.copy(copy)
easygui.msgbox('已保存到剪切板')
elif c == '重置':
break
elif c == '退出':
ex=1
break
else:
print('发生未知错误')
else:
print("请求失败,状态码:", response.status_code)
easygui.msgbox(f"感谢使用")
except:
tc = ["requests", "bs4",
"easygui", "pyperclip", "importlib"]
ml = []
for l in tc:
try:
importlib.import_module(l)
except ModuleNotFoundError:
ml.append(l)
if ml:
print("缺失的库:")
for li in ml:
print(li)
print('请补充相应的库')
else:
print("发生未知错误")
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn