Stack Exchange
Ошибка при парснге Python
При пробе запустить данный код:
# getting the html document
from urllib.request import urlopen
html = urlopen('https://drgn.site/double').read().decode('utf-8')
search_string = '<div class="left bg>'

# getting the right part of the code
number_string = html.find(search_string)
html = html[number_string:-1]
html = html[:10]
print(html)

Выходит данная ошибка:
Traceback (most recent call last):
  File "C:/Users/User/Desktop/test/number_one.py", line 3, in <module>
    html = urlopen('https://drgn.site/double').read().decode('utf-8')
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 532, in open
    response = meth(req, response)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 564, in error
    result = self._call_chain(*args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 756, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 532, in open
    response = meth(req, response)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 564, in error
    result = self._call_chain(*args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 756, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 532, in open
    response = meth(req, response)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 564, in error
    result = self._call_chain(*args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 756, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 532, in open
    response = meth(req, response)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 564, in error
    result = self._call_chain(*args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 756, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 532, in open
    response = meth(req, response)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 564, in error
    result = self._call_chain(*args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 746, in http_error_302
    self.inf_msg + msg, headers, fp)
urllib.error.HTTPError: HTTP Error 307: The HTTP server returned a redirect error that would lead to an infinite loop.
The last 30x error message was:
Temporary Redirect


Ну так английским по белому написано — бесконечный редирект. А бесконечный он потому, что сайт хочет установить куки, а вы их не обрабатываете, он и пытается бесконечно их установить
