coursera-using-python-to-access-web-data icon indicating copy to clipboard operation
coursera-using-python-to-access-web-data copied to clipboard

Calling a JSON API not working for new url

Open cgs434 opened this issue 7 years ago • 3 comments

for the new base url the program is not working

cgs434 avatar Jan 31 '19 19:01 cgs434

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)

pavithravairavasundaram avatar Oct 11 '19 09:10 pavithravairavasundaram

Urllib give error that there is no attributes urllib.urlopen

Shoaib-Siddiqui-Github avatar May 10 '20 07:05 Shoaib-Siddiqui-Github

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)

keshavgbpecdelhi avatar Nov 03 '21 10:11 keshavgbpecdelhi