代码

#导入模块 - import modular
from email import header
from bs4 import BeautifulSoup
import requests
#请求网站
f="《"
a="|"
n="1"
path="./1/new.txt"
while True:
url="https://so.gushiwen.cn/mingjus/default.aspx?page="+n+"1&tstr=&astr=&cstr=&xstr="
headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE'}
response=requests.get(url,headers=headers)
soup=BeautifulSoup(response.text,"lxml")
listResult=soup.find_all("a")
n=str(int(n)+1)
for i in listResult:
if len(i.text)>=5:
if not f in i.text:
if not a in i.text:
s=i.text
with open(path,"a") as file:
file.write(s)
if n=="5":
break