@kodbiprog

Как сохранить переменную после цикла For?

infos = soup2.find_all('div',class_="games_list_tabs")
UnboundLocalError: local variable 'soup2' referenced before assignment

During handling of the above exception, another exception occurred:

url = 'https://steamcommunity.com/'
			school = requests.get(url, cookies=jar, timeout=2, headers=headers).text
			soup = bs(school,'lxml')

			rows = soup.find_all('span',class_="pulldown global_action_link persona_name_text_content")
			rows2 = soup.find_all('a',class_="global_action_link")
			rows3 = soup.find_all('a',class_="menuitem supernav username persona_name_text_content")


			for username in rows:
				user = username.text.strip()

			for balance in rows2:
				money = balance.text.strip()
				if "login" in money:
					print(f"\n{Fore.RED}No VALID  -    {i}          {Fore.WHITE}\n")
				else:
					a = user
					print(f"\n{Fore.GREEN}VALID  -    {i}          {Fore.WHITE}")
					print(f"{Fore.YELLOW}{user}  {Fore.WHITE}|  {Fore.YELLOW}{money}{Fore.WHITE}\n")


			for link in rows3:
				link_steam = link.get('href')
				link_inventar_test = link_steam.split("/")
				link_inventar = link_inventar_test[4]
				inventar = requests.get(f"https://steamcommunity.com/profiles/{link_inventar}/inventory/", cookies=jar, headers=headers).text
				soup2 = bs(inventar,'lxml')


			infos = soup2.find_all('div',class_="games_list_tabs")

			for info in infos:
				text = info.text.strip()
				print(text)
  • Вопрос задан
  • 88 просмотров
Решения вопроса 1
sergey-gornostaev
@sergey-gornostaev Куратор тега Python
Седой и строгий
Очевидно, объявить её за пределами блока цикла.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы