import csv
import requests
from bs4 import BeautifulSoup
import csv
import re
url_list = ['https://basketball.realgm.com/player/player/Summary/1',
'https://basketball.realgm.com/player/player/Summary/2']
for url in url_list:
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
player = soup.find_all('div', class_='wrapper clearfix container')[0]
playerprofile = re.sub(
r'\n\s*\n', r'\n', player.get_text().strip(), flags=re.M)
print(playerprofile + "\n")
这段代码的工作方式如您所需的输出所示,似乎代码中播放器的解析和打印是在循环完成之后进行的。它应该为循环的每个迭代执行,所以您可以将它缩进循环中。