if filter_words in xxx
,即一个简单的匹配notepad++
,然后手动修饰成符合的列表样式with open('C:/Users/xxx/Desktop/filter_words.txt','r',encoding='utf-8') as f:
filter_words = [line.rstrip() for line in f] #处理那些一行就只有一个数据的文件时,就可以这样将每一行右侧空白符删除后写入列表
# -*- coding:utf-8 -*-
# Author:Konmu
# 第 0011 题: 敏感词文本文件 filtered_words.txt,里面的内容为以下内容,
# 当用户输入敏感词语时,则打印出 Freedom,否则打印出 Human Rights。
# 第 0012 题: 敏感词文本文件 filtered_words.txt,里面的内容 和 0011题一样,
#当用户输入敏感词语,则用 星号 * 替换,
# 例如当用户输入「北京是个好城市」,则变成「**是个好城市」。
with open('C:/Users/xxx/Desktop/filter_words.txt','r',encoding='utf-8') as f:
filter_words = [line.rstrip() for line in f]
def client_Input():
input_word = input("please input what you want to say:")
for i in filter_words:
if i in input_word:
print("Freedom")
new_word = input_word.replace(i,'*'*len(i))
return(new_word)
return('Human Rights')
if __name__ == "__main__":
print(client_Input())
# -*- coding:utf-8 -*-
# Author:Konmu
# 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-)
import requests
import re
url='https://tieba.baidu.com/p/2166231880?red_tag=0872956249'
session=requests.session()
#context=ssl._create_unverified_context()
html=session.get(url).content.decode('utf-8')
pattern=r'<img pic_type="0" class="BDE_Image" src=(.*?) .*?>'
img_url=re.findall(pattern,html)
#print(img_url)
x=0
for i in img_url:
i=i.replace('"','')
photo = requests.get(i)
with open('D:/py_tu/output{}.jpg'.format(x),'ab') as f:
f.write(photo.content)
x+=1
print("图片开始下载,注意查看文件夹")
urllib.request
的urlretrieve()
来下载图片的,但是发现urllib
无法处理https
,而且编译安装python
之前没有编译安装类似于openssl
这样的SSL
库,所以导致python
不支持SSL
,网上大多是针对Linux
的解决方法,对于windows
我尝试按照使用python
的ssl
库但是也没能解决,遂选择了直接保存文件,即上述代码中示例原文:https://www.cnblogs.com/Konmu/p/12539385.html