def main:
with open(sourcefile, 'r', encoding='utf-8') as main_file:
for line in main_file:
htmlcontent = reader(line)
def reader(line):
with urllib.request.urlopen(line) as url_file:
try:
url_file.read().decode('UTF-8')
except urllib.error.URLError as url_err:
print('Error opening url: ', url, url_err)
except UnicodeDecodeError as decode_err:
print('Error decoding url: ', url, decode_err)
return url_file
Hello everyone, I am pretty new to python and I have a question regarding reading the HTML code from a website. So I am using regular expressions as shown, and I am trying to simply return the HTML code from a website. The variable line
takes in URLs from a text file, which has lines of URL so it iterates through it. This is my code so far, but there are multiple errors that are popping up. I know that I have to use the else
clause, and I don't know how to incorporate that. I intend to use the returned HTML value as a subject for regex. I also hope to get the HTML using urllib.request library.