First of all this is my code:
import urllib.request, json
with urllib.request.urlopen("https://www.supremenewyork.com/mobile_stock.json") as url:
data = json.loads(url.read().decode())
print(type(data['Shoes']))
Im trying to parse the Json, that i get from the Supreme Website with Python. Im trying to filter out the 'Shoes' Array. Printing out the whole 'data' works, but if im trying to filter out the 'Shoes' Array, I get this Error:
Traceback (most recent call last):
File "C:\Users\-\PycharmProjects\-\test.py", line 7, in <module>
print(type(data['Shoes']))
KeyError: 'Shoes'
The Json is to long to store it here, but you will find it under:
https://www.supremenewyork.com/mobile_stock.json
print(data['products_and_categories']['Shoes'])
If you look at the json the Shoes are under products and categories:
data["products_and_categories"]["Shoes"]
this will get you the data you need
Related
I'm subscribed to skillshare but turns out skillshare's UI is a huge mess and unproductive for learning. So, I am seeking for a way to mass download course(single course) at once.
I found this github.
https://github.com/crazygroot/skillsharedownloader
And it has a google collab link as well at the bottom.
https://colab.research.google.com/drive/1hUUPDDql0QLul7lB8NQNaEEq-bbayEdE#scrollTo=xunEYHutBEv%2F
I'm getting the below error:
Traceback (most recent call last):
File "/root/Skillsharedownloader/ss.py", line 11, in <module>
dl.download_course_by_url(course_url)
File "/root/Skillsharedownloader/downloader.py", line 34, in download_course_by_url
raise Exception('Failed to parse class ID from URL')
Exception: Failed to parse class ID from URL
This is the course link that I'm using:
https://www.skillshare.com/en/classes/React-JS-Learn-by-examples/1186943986/
I have encountered a similar issue. The problem was that it requires the URL to look like https://www.skillshare.com/classes/.*?/(\d+).
If your copying the URL from the address bar, check the URL again and make sure it has the same format. The current one looks like https://www.skillshare.com/en/classes/xxxxx. So simply remove /en.
I need to get all the bodyHtml and authorId values from the file that appears here: https://drive.google.com/file/d/10EGOAWsw3G5-ETUryYX7__JPOfNwUsL6/view?usp=sharing
I have tried several ways, but I always find the error of: TypeError: list indices must be integers, not str
I've tried several ways, this is my last code:
# -*- coding: utf-8 -*-
import json
import requests
import datetime
data = json.loads(open('file.json').read())
coments = data['headDocument']['content']['id']
for comment in data['headDocument']['content']['content']['bodyHtml']:
info = comment
print(info)
and get this error:
Traceback (most recent call last):
File "coments.py", line 16, in <module>
for comment in data['headDocument']['content']['content']['bodyHtml']:
TypeError: list indices must be integers, not str
Can anyone help with this problem?
Your headDocument['content'] is a list, so you should loop through it. Like this:
for item in data['headDocument']['content']:
print(item['content']['bodyHtml'])
I'm currently trying to get data with python from the Internet. Fortunately the Website I want to Approach Hands me the data in json Format.
Now this is my Code:
from GetWebJson import simple_get
import json
raw_data = simple_get('http://api.openweathermap.org/data/2.5/weather?q=Hamburg,de')
raw_data.encoding
data_json = raw_data.json
print(data_json["temp"])
The simple_get function executes "Get" from the requests library and Returns the Response object.
After formatting the raw data to json In want to print the value of the key "temp". But when i debug this Code I get the following error:
Traceback (most recent call last):
File "C:\Users\nikhi\source\repos\WebScraper\WebScraper\WebScraper.py", line 7, in
print(data_json["temp"])
TypeError: 'method' object is not subscriptable
Can't I use the variable data_json like a dict? If not, how do I convert the json, which contains lists and dicts to a printable Format?
The code I'm trying to get working is:
h = str(heading)
# '<h1>Heading</h1>'
heading.renderContents()
I get this error:
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
print h.renderContents()
AttributeError: 'str' object has no attribute 'renderContents'
Any ideas?
I have a string with html tags and i need to clean it if there is a different way of doing that please suggest it.
Your error message and your code sample don't line up. You say you're calling:
heading.renderContents()
But your error message says you're calling:
print h.renderContents()
Which suggests that perhaps you have a bug in your code, trying to call renderContents() on a string object that doesn't define that method.
In any case, it would help if you checked what type of object heading is to make sure it's really a BeautifulSoup instance. This works for me with BeautifulSoup 3.2.0:
from BeautifulSoup import BeautifulSoup
heading = BeautifulSoup('<h1>heading</h1>')
repr(heading)
# '<h1>heading</h1>'
print heading.renderContents()
# <h1>heading</h1>
print str(heading)
# '<h1>heading</h1>'
h = str(heading)
print h
# <h1>heading</h1>
I'm trying to parse an RSS/Podcast feed using Beautifulsoup and everything is working nicely except I can't seem to parse the 'pubDate' field.
data = urllib2.urlopen("http://www.democracynow.org/podcast.xml")
dom = BeautifulStoneSoup(data, fromEncoding='utf-8')
items = dom.findAll('item');
for item in items:
title = item.find('title').string.strip()
pubDate = item.find('pubDate').string.strip()
The title gets parsed fine but when it gets to pubDate, it says:
Traceback (most recent call last):
File "", line 2, in
AttributeError: 'NoneType' object has no attribute 'string'
However, when I download a copy of the XML file and rename 'pubDate' to something else, then parse it again, it seems to work. Is pubDate a reserved variable or something in Python?
Thanks,
g
It works with item.find('pubdate').string.strip().
Why don't you use feedparser ?