基本上我现在试图从sortedOptions
部分只拉动所有SKU
。我被告知这是json,不确定这是否正确。现在我只是拉第一个。我需要指定什么来吸引所有人? 我最初尝试使用正则表达式,并没有拉任何信息,然后我被告知它是json,我需要使用json。到目前为止,这是我以前唯一能够从网站上获取任何东西的方法。将变量从站点拉出来,使用相同的名称
那么我的下一步就是将stock status
和name
只在同一部分。
CODE:从网站输出
import requests
import json
r = requests.get('https://randomwebsite.com/')
pull = r.json()
print " "
string = json.dumps(pull)
parsed_json = json.loads(string)
print parsed_json['name']
print parsed_json['SKU']
:
{
"ID": "281460",
"SKU": "281460",
"isVisible": true,
"isOption": false,
"parentSKU": null,
"trackingSKU": "281460",
"name": "NIKE Air Vapormax",
"model": null,
"brand": {
"id":
"ID": "9D63FD8C31DBD53AB2A9D51F4D9DBBCA",
"name": "NIKE",
"clientID": null,
"sortOrder": null,
"image": null,
"target": "",
"filters": {
"brandname": "nike"
}
},
"sortedOptions": [
{
"name": "5.5",
"product": {
"SKU": "281460.463725",
"isDefault": false,
"price": {
"amount": "180.00",
"currency": "GBP"
},
"previousPrice": null,
"RRP": {
"amount": "180.00",
"currency": "GBP"
},
"costPrice": null,
"taxCode": null,
"taxRate": null,
"stockStatus": "IN STOCK",
"colour": "",
"colourDescription": "GRY/GRY-SPECK",
"size": null,
"exactSize": null,
"sortOrder": "1",
"optionTypes": [
"UK Size"
]
},
"isLeaf": true
},
{
"name": "6",
"product": {
"SKU": "281460.595347",
"isDefault": false,
"price": {
"amount": "180.00",
"currency": "GBP"
},
"previousPrice": null,
"RRP": {
"amount": "180.00",
"currency": "GBP"
},
"costPrice": null,
"taxCode": null,
"taxRate": null,
"stockStatus": "IN STOCK",
"colour": "",
"colourDescription": "GRY/GRY-SPECK",
"size": null,
"exactSize": null,
"sortOrder": "2",
"optionTypes": [
"UK Size"
]
},
"isLeaf": true
},
{
"name": "6.5",
"product": {
"SKU": "281460.463895",
"isDefault": false,
"price": {
"amount": "180.00",
"currency": "GBP"
},
"previousPrice": null,
"RRP": {
"amount": "180.00",
"currency": "GBP"
},
"costPrice": null,
"taxCode": null,
"taxRate": null,
"stockStatus": "IN STOCK",
"colour": "",
"colourDescription": "GRY/GRY-SPECK",
"size": null,
"exactSize": null,
"sortOrder": "3",
"optionTypes": [
"UK Size"
]
},
"isLeaf": true
},
{
"name": "7.5",
"product": {
"SKU": "281460.595350",
"isDefault": false,
"price": {
"amount": "180.00",
"currency": "GBP"
},
"previousPrice": null,
"RRP": {
"amount": "180.00",
"currency": "GBP"
},
"costPrice": null,
"taxCode": null,
"taxRate": null,
"stockStatus": "IN STOCK",
"colour": "",
"colourDescription": "GRY/GRY-SPECK",
"size": null,
"exactSize": null,
"sortOrder": "5",
"optionTypes": [
"UK Size"
]
},
"isLeaf": true
},
{
"name": "8",
"product": {
"SKU": "281460.595352",
"isDefault": false,
"price": {
"amount": "180.00",
"currency": "GBP"
},
"previousPrice": null,
"RRP": {
"amount": "180.00",
"currency": "GBP"
},
"costPrice": null,
"taxCode": null,
"taxRate": null,
"stockStatus": "IN STOCK",
"colour": "",
"colourDescription": "GRY/GRY-SPECK",
"size": null,
"exactSize": null,
"sortOrder": "6",
"optionTypes": [
"UK Size"
]
},
"isLeaf": true
},
{
"name": "9",
"product": {
"SKU": "281460.595359",
"isDefault": false,
"price": {
"amount": "180.00",
"currency": "GBP"
},
"previousPrice": null,
"RRP": {
"amount": "180.00",
"currency": "GBP"
},
"costPrice": null,
"taxCode": null,
"taxRate": null,
"stockStatus": "IN STOCK",
"colour": "",
"colourDescription": "GRY/GRY-SPECK",
"size": null,
"exactSize": null,
"sortOrder": "8",
"optionTypes": [
"UK Size"
]
},
"isLeaf": true
},
为什么你要转换的对象,把它们变回JSON字符串,然后再回到对象? – jonrsharpe
它给了我一个错误,指出它需要是一个字符串,如果你有一个更直接的方法,请让我知道。这是我能够从此页面获取信息的唯一途径 –
您的代码无法使用。 –