Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling a JSON API not working for new url #2

Open
cgs434 opened this issue Jan 31, 2019 · 3 comments
Open

Calling a JSON API not working for new url #2

cgs434 opened this issue Jan 31, 2019 · 3 comments

Comments

@cgs434
Copy link

cgs434 commented Jan 31, 2019

for the new base url the program is not working

@pavithravairavasundaram

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)

@Shoaib-Siddiqui-Github
Copy link

Urllib give error that there is no attributes urllib.urlopen

@keshavgbpecdelhi
Copy link

keshavgbpecdelhi commented Nov 3, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants