Http request in python

from urllib import *

from bs4 import BeautifulSoup

url = input(‘Enter -’)

html = request.urlopen (url).read()

soup = BeautifulSoup(html)

tag = soup(‘a’)

for tag in tags:

print(tag.get('herf',None))

i did it but when i give url -----https://guides.gamepressure.com/assassins-creed-odyssey/guide.asp?ID=49443

it is showing error like


HTTPError Traceback (most recent call last)
in
5 url = input(‘Enter -’)
6
----> 7 html = request.urlopen (url).read()
8
9 soup = BeautifulSoup(html)

/usr/local/anaconda/lib/python3.6/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
221 else:
222 opener = _opener
–> 223 return opener.open(url, data, timeout)
224
225 def install_opener(opener):

/usr/local/anaconda/lib/python3.6/urllib/request.py in open(self, fullurl, data, timeout)
530 for processor in self.process_response.get(protocol, []):
531 meth = getattr(processor, meth_name)
–> 532 response = meth(req, response)
533
534 return response

/usr/local/anaconda/lib/python3.6/urllib/request.py in http_response(self, request, response)
640 if not (200 <= code < 300):
641 response = self.parent.error(
–> 642 ‘http’, request, response, code, msg, hdrs)
643
644 return response

/usr/local/anaconda/lib/python3.6/urllib/request.py in error(self, proto, *args)
568 if http_err:
569 args = (dict, ‘default’, ‘http_error_default’) + orig_args
–> 570 return self._call_chain(*args)
571
572 # XXX probably also want an abstract factory that knows when it makes

/usr/local/anaconda/lib/python3.6/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
502 for handler in handlers:
503 func = getattr(handler, meth_name)
–> 504 result = func(*args)
505 if result is not None:
506 return result

/usr/local/anaconda/lib/python3.6/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
648 class HTTPDefaultErrorHandler(BaseHandler):
649 def http_error_default(self, req, fp, code, msg, hdrs):
–> 650 raise HTTPError(req.full_url, code, msg, hdrs, fp)
651
652 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 403: Forbidden

how can i fix it

Please go through the below discussion:

it is showing me error.

def average_spam_confidence():

with open('mbox-short.txt') as f:

    count = 0

    spam_confidence_sum = 0

    

for line in f:
    
    line = line.rstrip()
    
    if line.startswith('X-DSPAM-Confidence:'):
        
        var ,value = line.split(':')
        
        spam_confidence_sum = spam_confidence_sum + float(value)
        
        count += 1
        
        avg = spam_confidence_sum / count
        
        return  avg
    
    
    average_spam_confidence()

ValueError Traceback (most recent call last)
in
----> 1 average_spam_confidence()

in average_spam_confidence()
9
10
—> 11 for line in f:
12
13 line = line.rstrip()

ValueError: I/O operation on closed file.


How can i fix it?

Is this query related to the previous one? If yes, then could you please elaborate? If no, then would request you to open a new thread for a new topic.