I need my code to have a new link so that it could parse and print a list of new titles from articles.
How to loop part of code so that it iterated over options from 1 to 10 switching to a new link each time?
import urllib.request
from bs4 import BeautifulSoup
import re
for n in range(1,11):
url = f"https://habr.com/ru/articles/{n}/"
fp = urllib.request.urlopen(url)
mybytes = fp.read()
mystr = mybytes.decode("utf8")
fp.close()
def title(input_string):
pattern = r'<title>(.+?)</title>'
match = re.search(pattern, input_string)
if match:
return match.group(1)
else:
return None
print(title(mystr))