coursera-using-python-to-access-web-data
coursera-using-python-to-access-web-data copied to clipboard
Calling a JSON API not working for new url
for the new base url the program is not working
Yes, it shows the below traceback error. json_obj = json.loads(data) obj, end = self.raw_decode(s, idx=_w(s, 0).end()) raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Urllib give error that there is no attributes urllib.urlopen
Try this @cgs434 @Shoaib-Siddiqui-Github @WenlinH :
# To run this, download the BeautifulSoup zip file
# http://www.py4e.com/code3/bs4.zip
# and unzip it in the same directory as this file
from urllib.request import urlopen
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 URL - ')
rep = int(input('Enter count: '))
pos = int(input('Enter position: '))
#intializing
count=0
# Retrieve all of the anchor tags
def parse(url):
html = urlopen(url, context=ctx).read()
soup = BeautifulSoup(html, "html.parser")
tags=soup('a')
return tags
while count<rep:
print('Retrieving:', url)
tags = parse(url)
for i,j in enumerate(tags):
if i==pos-1:
url = j.get('href', None)
name = j.contents[0]
break
else:
continue
count+=1
print('Name',name)