import requests #导入requests包 from bs4 import BeautifulSoup import os images = [] # data_list = {} texts = "" for i in range(1,250): url = 网址+str(i)+'/' print(url) requests.adapters.DEFAULT_RETRIES = 5 # 增加重连次数 s = requests.session() s.keep_alive = False # 关闭多余连接 strhtml = s.get(url) # Get方式获取网页数据 soup=BeautifulSoup(strhtml.text,'html.parser') datas = soup.find_all("a",class_ = "entry-title-link") for data in datas: # title_link = data.find(class_="").get("herf") # print(data["href"]) print(data["href"]) texts = texts + os.linesep + data["href"] f = open('title_link.txt', 'w+') # os.linesep代表当前操作系统上的换行符 f.write(texts) f.close()
import requests from bs4 import BeautifulSoup f = open('title_link.txt'