如何使用python中的beautifulsoup在python中循环URL

如何使用python中的beautifulsoup在python中循环URL,python,html,url,beautifulsoup,Python,Html,Url,Beautifulsoup,所以我有这个代码,我从某个网站上提取进球数。我想循环它,这样我就可以得到每个玩家的信息,例如:,然后,然后最多5000个。我该怎么做呢?这是我如何获取目标信息的代码 url = 'https://www.futbin.com/20/player/143/cristiano-ronaldo' response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') googclose = soup.find_al

所以我有这个代码,我从某个网站上提取进球数。我想循环它,这样我就可以得到每个玩家的信息,例如:,然后,然后最多5000个。我该怎么做呢?这是我如何获取目标信息的代码

url = 'https://www.futbin.com/20/player/143/cristiano-ronaldo'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
googclose = soup.find_all(class_='ps4-pgp-data')
hi=soup.find_all('div', attrs={'class':'ps4-pgp-data'})[4]

接受发送的评论(代码需要格式化以便于阅读),因此如果我正确理解您的问题,您可以创建一个球员姓名或ID列表,如
['1','2','3']
,,使用变量
player\u id
在列表中循环,并使用
url>创建
url
https://www.futbin.com/20/player/“+player_id
,其余代码在循环中保持不变。
all_goals=[] 

for i in range(1,51):
    url = 'https://www.futbin.com/20/player/{}'.format(i)
    response = requests.get(url) 
    soup = BeautifulSoup(response.text, 'html.parser')
    goal=soup.find_all('div', attrs={'class':'ps4-pgp-data'})[4].text.strip()
    all_goals.append(goal)