#导入模块 - import modular from email import header from bs4 import BeautifulSoup import requests #请求网站 f="《" a="|" n="1" path="./1/new.txt" whileTrue: 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: iflen(i.text)>=5: ifnot f in i.text: ifnot a in i.text: s=i.text withopen(path,"a") as file: file.write(s) if n=="5": break