0

My code is very simple:

from urllib.request import urlopen

quest = input("question link: ").strip()
page = urlopen(quest).read().decode()

I want the user to input an url and to store the raw data of it, in page, but when I try to run it with an url like this https://stackoverflow.com/questions/74783398/pyqt-app-doesnt-exit-when-i-close-the-window it returns to me an error saying that it couldn't decode a byte:

Traceback (most recent call last):
  File "C:\Users\Student\sofCheck.py", line 14, in <module>
    if search(page, "<body class=\"question-page"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Student\AppData\Local\Programs\Python\Python311\Lib\re\__init__.py", line 176, in search
    return _compile(pattern, flags).search(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Student\AppData\Local\Programs\Python\Python311\Lib\re\__init__.py", line 294, in _compile
    p = _compiler.compile(pattern, flags)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Student\AppData\Local\Programs\Python\Python311\Lib\re\_compiler.py", line 743, in compile
    p = _parser.parse(p, flags)
        ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Student\AppData\Local\Programs\Python\Python311\Lib\re\_parser.py", line 980, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Student\AppData\Local\Programs\Python\Python311\Lib\re\_parser.py", line 455, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Student\AppData\Local\Programs\Python\Python311\Lib\re\_parser.py", line 863, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Student\AppData\Local\Programs\Python\Python311\Lib\re\_parser.py", line 455, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Student\AppData\Local\Programs\Python\Python311\Lib\re\_parser.py", line 612, in _parse
    raise source.error(msg, len(this) + 1 + len(that))
re.error: bad character range t-p at position 20988 (line 328, column 219)

How can I fix it? Thanks.

Wolf
  • 17
  • 4

0 Answers0