У меня есть следующий код:
def get_songs_link(link_of_artist):
r = requests.get(link_of_artist).text
sleep(randint(4,8))
obj = BeautifulSoup(r, 'html.parser')
album={}
for item in obj.select("#listAlbum > .album"):
name = item.text
songs = []
for song in item.find_next_siblings('div', class_="listalbum-item"):
if song.find_previous_sibling('div', class_='album') == item:
songs.append([song.text, 'https://www.azlyrics.com/' + song.find('a')['href'][3:]])
album[name] = songs
return album
list_link_artist_1 = ['https://www.azlyrics.com/f/floyda1bentley.html',
'https://www.azlyrics.com/a/a.html',
'https://www.azlyrics.com/s/snohaalegra.html',
'https://www.azlyrics.com/a/aaliyah.html']
#------------------
liz = []
for link in list_link_artisti_1):
song_dict = get_songs_link(link)
liz.append(song_dict)
список ссылок имеет len = 1000.
, когда я запускаю скрипт через несколько раз (он меняется, первый раз после 5 минут, второй раз через 10 минут) это вызывает те ошибки:
3%|▎ | 26/1000 [03:52<2:19:38, 8.60s/it]Traceback (most recent call last):
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\urllib3\connectionpool.py", line 672, in urlopen
chunked=chunked,
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\urllib3\connectionpool.py", line 376, in _make_request
self._validate_conn(conn)
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\urllib3\connectionpool.py", line 994, in _validate_conn
conn.connect()
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\urllib3\connection.py", line 360, in connect
ssl_context=context,
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\urllib3\util\ssl_.py", line 370, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Program Files\Python37\lib\ssl.py", line 412, in wrap_socket
session=session
File "C:\Program Files\Python37\lib\ssl.py", line 850, in _create
self.do_handshake()
File "C:\Program Files\Python37\lib\ssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
TimeoutError: [WinError 10060] Impossibile stabilire la connessione. Risposta non corretta della parte connessa dopo l'intervallo di tempo oppure mancata risposta dall'host collegato
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\urllib3\connectionpool.py", line 720, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\urllib3\util\retry.py", line 400, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\urllib3\packages\six.py", line 734, in reraise
raise value.with_traceback(tb)
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\urllib3\connectionpool.py", line 672, in urlopen
chunked=chunked,
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\urllib3\connectionpool.py", line 376, in _make_request
self._validate_conn(conn)
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\urllib3\connectionpool.py", line 994, in _validate_conn
conn.connect()
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\urllib3\connection.py", line 360, in connect
ssl_context=context,
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\urllib3\util\ssl_.py", line 370, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Program Files\Python37\lib\ssl.py", line 412, in wrap_socket
session=session
File "C:\Program Files\Python37\lib\ssl.py", line 850, in _create
self.do_handshake()
File "C:\Program Files\Python37\lib\ssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: ('Connection aborted.', TimeoutError(10060, "Impossibile stabilire la connessione. Risposta non corretta della parte connessa dopo l'intervallo di tempo oppure mancata risposta dall'host collegato", None, 10060, None))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\IPython\core\interactiveshell.py", line 3331, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-103-290a8e4bc6a4>", line 2, in <module>
song_dict = get_songs_link(link)
File "<ipython-input-100-58ca37897386>", line 2, in get_songs_link
r = requests.get(link_of_artist).text
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\requests\sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\requests\adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', TimeoutError(10060, "Impossibile stabilire la connessione. Risposta non corretta della parte connessa dopo l'intervallo di tempo oppure mancata risposta dall'host collegato", None, 10060, None))
что вы думаете, это может быть? У меня действительно нет идеи, я новичок в python и веб-скребке, как это, но мы должны сдать экзамен, готовя проект с этим материалом. , .
спасибо большое! : D