Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def recursive_request(urlb, attempts):
- data = None
- response = getHtml(urlb)
- print(urlb + " #" + str(attempts))
- if response is not None:
- if response.status_code == 200:
- soup = BeautifulSoup(response.text, 'html.parser')
- # print(response)
- # print(soup)
- h1 = soup.find('h1')
- captcha = h1.find('br')
- print(h1.text + " #" + str(attempts))
- if captcha is None:
- fact = []
- div = soup.find_all('div', {'class': 'params'})
- if len(div) > 0:
- div = div[len(div) - 1]
- info = div.find('table', {'class': 'info'})
- if info is not None:
- td = (soup.find_all('td', {'class': 'card_info'}))
- if td is not None:
- td = td[2].find('table')
- if td is not None:
- td = td.find_all('a')
- if td is not None or td is not []:
- for t in td:
- fact.append(t.text)
- tr = info.find_all('tr')
- if len(tr) == 5:
- # print(h1.find('nobr').text)
- # print((tr[0].find_all('td'))[1].text)
- # print((tr[1].find_all('td'))[1].text)
- data = {
- 'mark': h1.find('nobr').text,
- 'weight': (tr[0].find_all('td'))[1].text,
- 'diam': (tr[1].find_all('td'))[1].text,
- "factories": fact
- }
- print("OOOKKKKK")
- print(data)
- print("---------------------------------------------------------------------------------->")
- return attempts
- else:
- print("Cannot connect #" + str(attempts))
- recursive_request(urlb, attempts)
- attempts -= 1
- if attempts == 0:
- return data
- else:
- recursive_request(urlb, attempts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement