Не могу понять из-за чего не кончается цикл, sleep из-за этого же не работает.
import requests
from bs4 import BeautifulSoup
import time
URL = 'https://www.wowprogress.com/gearscore/?lfg=1&raids_week=&lang=ru&sortby=ts'
HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36 OPR/75.0.3969.267', 'accept':'*/*'}
HOST = 'https://www.wowprogress.com'
CharURL = ''
NumberC = 0
NameP = ''
CharG = ''
CharCom = ''
CharClass = ''
CharRio = ''
CharCov =''
CharGS = ''
CharServ = '' #name plus server
#CharArmory = ''
CharF = ''
CharEXP = ''
RPW = ''
CharSpec = ''
# FactionList ={
# 'rio-faction-color--alliance': "Alliance",
# 'rio-faction-color--horde': "Horde"
# }
RIOhost = 'https://raider.io/characters/eu/'
realmList = {
"EU (RU)-Свежеватель Душ": "soulflayer/",
"EU (RU)-Ревущий фьорд": "howling-fjord/",
"EU (RU)-Ясеневый лес": "Ashenvale",
"EU (RU)-Гордунни": "gordunni/",
}
def get_html(url, params=None):
r = requests.get(url, headers=HEADERS, params=params)
return r
def get_content(html):
global CharURL
global NameP
soup = BeautifulSoup(html, 'lxml')
items = soup.find('table', class_='rating').find_all('tr')
chars = []
for item in items:
chars.append({
'nick': item.find('a', class_='hint--bottom-right').text,
'link': item.find('a', class_='hint--bottom-right').get('href'),
'serv': item.find('a', class_='realm').text
})
# провка на схожесть
global NumberC
while NumberC <= 22:
w = (chars[NumberC]['nick'] + ' ' + chars[NumberC]['serv'])
f = open('player_base.txt')
text = f.read()
if w in text:
break
else:
f = open('player_base.txt', 'a')
#f.write('\n' + w)
f.close()
global CharServ
CharServ = (chars[NumberC]['serv'])
NameP = (chars[NumberC]['nick'])
CharURL = (HOST + chars[NumberC]['link'])
html = get_html(CharURL)
if html.status_code == 200:
get_charcontent(html.text)
else:
print('error')
### Код для конкретного чара ###
def get_html(url, params=None):
r = requests.get(url, headers=HEADERS)
return r
def get_charcontent(html):
soup = BeautifulSoup(html, 'lxml')
persons = soup.findAll('div', class_='primary')
person = []
global CharGS
global CharG
global CharCom
global CharClass
# global RPW
# global CharSpec
# global CharArmory
for item in persons:
guild = item.find('a', class_='guild')
if guild:
guild = guild.text
else:
guild = ''
coment = item.find('div', class_='charCommentary')
if coment:
coment = coment.text
else:
coment = ''
ilvl = item.find('div', class_='gearscore')
if ilvl:
ilvl = ilvl.text
else:
ilvl = 'Не определен'
# rpw = item.find('div', class_='raiding_style').find_next('div').text
# if rpw:
# rpw = rpw
# else:
# rpw = ''
# spec = item.find('div', class_='raiding_style').text
# if spec:
# spec = spec.text
# else:
# spec = ''
person = {
'server': item.find('a', class_='nav_link').text,
'guild': guild,
'ilvl': ilvl,
'coment': coment,
'class': item.find('i').text.replace(' 60', ''),
'armory': item.find('a', class_='armoryLink').get('href'),
# 'rpw': rpw,
# 'Spec': item.find('div', class_='language').text
}
CharGS = (person['ilvl'])
CharG = (person['guild'])
CharCom = (person['coment'])
CharClass = (person['class'])
# CharSpec = (person['Spec'])
# RPW = (person['rpw'])
##RIo##
global RIOurl
global realmList
RIOurl = (RIOhost + (realmList[CharServ]) + NameP)
html = get_html(RIOurl)
if html.status_code == 200:
get_riocharcontent(html.text)
else:
print('error')
def get_riocharcontent(html):
soup = BeautifulSoup(html, 'lxml')
riopersons = soup.findAll('div', class_='slds-grid slds-wrap slds-grid--vertical-align-center rio-masthead--content-top')
riop = []
global CharRio
global CharCov
global CharF
global CharEXP
for item in riopersons:
riop = {
'rio': item.find('span',class_='rio-badge-size--medium slds-badge rio-badge rio-badge-color--light rio-border--light rio-shadow--small rio-text-shadow--normal').text,
'cov': item.find('div', class_='nowrap text-bold').text,
'fac': item.find('span').get('class'),
'exp': item.find('div', class_='slds-text-body--small').find_next('div').text
}
CharEXP = (riop['exp'][0] + riop['exp'][1] + riop['exp'][2] + riop['exp'][3] + riop['exp'][4] + riop['exp'][5])
CharRio = (riop['rio'])
CharCov = (riop['cov'])
CharF = (riop['fac'][1])
# print(NameP + ' - ' + CharF.replace('rio-faction-color--', '') + ' - ' + CharServ)
# print(CharEXP)
# print(CharClass) # + ' - ' + CharSpec)
# print(CharGS)
# print('Covenant: ' + CharCov)
# print('RIO: ' + CharRio)
# print('Current Guild: ' + CharG)
# print('Discription: ' + CharCom)
# # print(RPW)
# print(CharURL)
#print(riopersons)
def parse():
html = get_html(URL)
if html.status_code == 200:
get_content(html.text)
else:
print('error')
while True:
NumberC = 0
print('KekW') #тест
time.sleep(10)
while NumberC <= 1: #1 для теста. Должно быть 22
parse()
NumberC += 1
#time.sleep(10)
# while True:
# NumberC = 0
# parse()
# time.sleep(10)