import urllib.request from bs4 import BeautifulSoup import time url = 'https://yuncode.net/list/python' for page in range(1, 10): # 这里假设要爬的分页数最多10页 pageUrl = url + '?&p=' + str(page) pageHtml = urllib.request.urlopen(pageUrl).read() pageSoup = BeautifulSoup(pageHtml, "lxml") titleList = pageSoup.find_all('div', class_='title_title') for item in titleList: print(item.text) # 每个条目的标题 time.sleep(1)