I am a beginner Python programmer. For practice, I am trying to get a list of article titles and their URLs from a webpage. So far, I have come up with up with this code:
import requests
from bs4 import BeautifulSoup as BS
with requests.session() as r:
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0'}
r = requests.get('https://0xdf.gitlab.io', verify=False, headers=headers)
response = r.text
soup = BS(response, 'html.parser')
tags = soup.find_all('a')
for tag in tags:
links = tag.get('href')
if links[0] == '/':
appended_link = 'https://0xdf.gitlab.io' + links
print(appended_link)
elif links[0] == '#':
pass
else:
print(links)
However, it doesn't extract what I am interested in. I want the title of the articles alongside its full URL.
Thanks