SHOW:
|
|
- or go back to the newest paste.
1 | - | fact = [] |
1 | + | def recursive_request(urlb, attempts): |
2 | data = None | |
3 | response = getHtml(urlb) | |
4 | print(urlb + " #" + str(attempts)) | |
5 | if response is not None: | |
6 | if response.status_code == 200: | |
7 | soup = BeautifulSoup(response.text, 'html.parser') | |
8 | # print(response) | |
9 | # print(soup) | |
10 | h1 = soup.find('h1') | |
11 | captcha = h1.find('br') | |
12 | print(h1.text + " #" + str(attempts)) | |
13 | ||
14 | if captcha is None: | |
15 | fact = [] | |
16 | div = soup.find_all('div', {'class': 'params'}) | |
17 | if len(div) > 0: | |
18 | div = div[len(div) - 1] | |
19 | info = div.find('table', {'class': 'info'}) | |
20 | ||
21 | if info is not None: | |
22 | td = (soup.find_all('td', {'class': 'card_info'})) | |
23 | if td is not None: | |
24 | td = td[2].find('table') | |
25 | if td is not None: | |
26 | td = td.find_all('a') | |
27 | if td is not None or td is not []: | |
28 | for t in td: | |
29 | fact.append(t.text) | |
30 | ||
31 | tr = info.find_all('tr') | |
32 | - | return data |
32 | + | |
33 | # print(h1.find('nobr').text) | |
34 | # print((tr[0].find_all('td'))[1].text) | |
35 | # print((tr[1].find_all('td'))[1].text) | |
36 | ||
37 | data = { | |
38 | 'mark': h1.find('nobr').text, | |
39 | 'weight': (tr[0].find_all('td'))[1].text, | |
40 | 'diam': (tr[1].find_all('td'))[1].text, | |
41 | "factories": fact | |
42 | } | |
43 | print("OOOKKKKK") | |
44 | print(data) | |
45 | print("---------------------------------------------------------------------------------->") | |
46 | return attempts | |
47 | ||
48 | else: | |
49 | print("Cannot connect #" + str(attempts)) | |
50 | recursive_request(urlb, attempts) | |
51 | attempts -= 1 | |
52 | if attempts == 0: | |
53 | return data | |
54 | else: | |
55 | recursive_request(urlb, attempts) |