用户:
小鱼队长查看:0 回复:0 评论:0 创建时间:2021-07-18T14:33:37
【作品展示】

【作品介绍】
两个功能
【作品源代码】
import requests
import easygui
import bs4
# 一代传送门:ht啊tps啊:啊/啊/一shequ.代codemao.网cn/的community/链384586接
# 二代传送门:ht啊tps啊:啊/啊/一shequ.代codemao.网cn/的community/链385075接
# 三代传送门:ht啊tps啊:啊/啊/一shequ.代codemao.网cn/的community/链385452接
# 注意:吧“啊啊啊啊一代网的链接”这些字删掉就行了
h = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win喵; x喵) AppleWebKit/537.36 (KH喵L, ''like Gecko)Chrome/69.0.3497.100 Safari/537.36'}
# 注意:吧“和”删掉
if easygui.ynbox('欢迎使用爬虫程序', '', ('获取xx标签的内容', '获取网页代码')) == False:
url = 'http://' + str(easygui.enterbox('获取网页的网址(不要HTTP开头的)'))
r = requests.get(url, headers=h)
if r.status_code == 200:
r.encoding = r.apparent_encoding
print(r.text)
elif r.status_code == 500:
print('服务器出现错误')
elif r.status_code == 404:
print('404 NOT FIND')
else:
print('出现异常爬取')
else:
url = 'http://' + str(easygui.enterbox('网页的网址(不要HTTP开头的)'))
r = requests.get(url, headers=h)
if r.status_code == 200:
soup = bs4.BeautifulSoup(r.text, 'html.parser', from_encoding='utf-8')
tagList = soup.select(str(easygui.enterbox('标签')))
for tag in tagList:
print(tag.text)
elif r.status_code == 500:
print('服务器出现错误')
elif r.status_code == 404:
print('404 NOT FOUND')
else:
print('出现异常爬取')
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn