Getting Anchor tags information from http:// or https:// website

17 Views Asked by At

My code is acting strange, I am trying to run this code:

The only problem is that it doesn't print out anything for this specific link I have to do this assignment but, if I use a different URL it prints out all the relevant information about it. Here is the link I'm trying to use currently: http://py4e-data.dr-chuck.net/comments_1870821.html

import urllib.request, urllib.parse, urllib.error
from bs4 import BeautifulSoup
import ssl

#Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE


url = input("Enter: ")
html = urllib.request.urlopen(url, context=ctx).read()
soup = BeautifulSoup(html, 'html.parser')

#Retrieve all of the anchor tags
tags = soup('a')
for tag in tags:
    print(tag.get('href', None))

I've tried deriving the sum of the whole anchor tags with a code like with sums but nothing pops up and when I debug it, it shows it's running normally. I don't know what I'm doing wrong

Hopefully someone can help me.

Thanks, DM

0

There are 0 best solutions below