from woocommerce import API
import json
wcapi = API(
url=u"https://какой-то сайт.ru",
consumer_key="ck_...",
consumer_secret="cs_...",
wp_api=True,
version="wc/v2",
query_string_auth=True # Force Basic Authentication as query string true and using under HTTPS
)
r: list[object] = wcapi.get("products", params={'per_page': 1, 'status': 'publish'}).json()
content="summary_large_image" />\n<meta name="twitter:label1" content="Примерное время для чтения">\n\t<meta name="twitter:data1" content="1 минута">\n<script type="application/ld+json" class="yoast-schema-graph">{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://streetclimate.ru/#organization","name":"\\u0421\\u0442\\u0440\\u0438\\u0442-\\u041a\\u043b\\u0438\\u043c\\u0430\\u0442","url":"https://какой-то сайт.ru/","sameAs":[],"logo":{"@type":"ImageObject","@id":"https://какой-то сайт.ru/#logo","inLanguage":"ru-RU","url":"https://какой-то сайт.ru/wp-content/uploads/2018/12/3_White_logo_on_color1_269x67.png","width":269,"height":67,"caption":"\\u0421\\u0442\\u0440\\u0438\\u0442-\\u041a\\u043b\\u0438\\u043c\\u0430\\u0442"},"image":{"@id":"https://какой-то сайт.ru/#logo"}},{"@type":"WebSite","@id":"https://какой-то сайт.ru/#website","url":"https://какой-то сайт.ru/","name":"\\u0421\\u0442\\u0440\\u0438\\u0442-\\u041a\\u043b\\u0438\\u043c\\u0430\\u0442","description":"\\u041f\\u0440\\u043e\\u0434\\u0430\\u0436\\u0430, \\u0443\\u0441\\u0442\\u0430\\u043d\\u043e\\u0432\\u043a\\u0430 \\u0438 \\u043e\\u0431\\u0441\\u043b\\u0443\\u0436\\u0438\\u0432\\u0430\\u043d\\u0438\\u0435 \\u043a\\u043e\\u043d\\u0434\\u0438\\u0446\\u0438\\u043e\\u043d\\u0435\\u0440\\u043e\\u0432, \\u0441\\u043f\\u043b\\u0438\\u0442-\\u0441\\u0438\\u0441\\u0442\\u0435\\u043c \\u0438 \\u0442\\u0435\\u043f\\u043b\\u043e\\u0432\\u044b\\u0445 \\u0437\\u0430\\u0432\\u0435\\u0441 \\u0432 \\u0421\\u041f\\u0431 \\u0438 \\u041b\\u0435\\u043d\\u0438\\u043d\\u0433\\u0440\\u0430\\u0434\\u0441\\u043a\\u043e\\u0439 \\u043e\\u0431\\u043b\\u0430\\u0441\\u0442\\u0438.",
>>> qq='content="summary_large_image" />\n<meta name="twitter:label1" content="Примерное время для чтения">\n\t<meta name="twitter:data1" content="1 минута">\n<script type="application/ld+json" class="yoast-schema-graph">{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://streetclimate.ru/#organization","name":"\\u0421\\u0442\\u0440\\u0438\\u0442-\\u041a\\u043b\\u0438\\u043c\\u0430\\u0442","url":"https://какой-то сайт.ru/","sameAs":[],"logo":{"@type":"ImageObject","@id":"https://какой-то сайт.ru/#logo","inLanguage":"ru-RU","url":"https://какой-то сайт.ru/wp-content/uploads/2018/12/3_White_logo_on_color1_269x67.png","width":269,"height":67,"caption":"\\u0421\\u0442\\u0440\\u0438\\u0442-\\u041a\\u043b\\u0438\\u043c\\u0430\\u0442"},"image":{"@id":"https://какой-то сайт.ru/#logo"}},{"@type":"WebSite","@id":"https://какой-то сайт.ru/#website","url":"https://какой-то сайт.ru/","name":"\\u0421\\u0442\\u0440\\u0438\\u0442-\\u041a\\u043b\\u0438\\u043c\\u0430\\u0442","description":"\\u041f\\u0440\\u043e\\u0434\\u0430\\u0436\\u0430, \\u0443\\u0441\\u0442\\u0430\\u043d\\u043e\\u0432\\u043a\\u0430 \\u0438 \\u043e\\u0431\\u0441\\u043b\\u0443\\u0436\\u0438\\u0432\\u0430\\u043d\\u0438\\u0435 \\u043a\\u043e\\u043d\\u0434\\u0438\\u0446\\u0438\\u043e\\u043d\\u0435\\u0440\\u043e\\u0432, \\u0441\\u043f\\u043b\\u0438\\u0442-\\u0441\\u0438\\u0441\\u0442\\u0435\\u043c \\u0438 \\u0442\\u0435\\u043f\\u043b\\u043e\\u0432\\u044b\\u0445 \\u0437\\u0430\\u0432\\u0435\\u0441 \\u0432 \\u0421\\u041f\\u0431 \\u0438 \\u041b\\u0435\\u043d\\u0438\\u043d\\u0433\\u0440\\u0430\\u0434\\u0441\\u043a\\u043e\\u0439 \\u043e\\u0431\\u043b\\u0430\\u0441\\u0442\\u0438.",'
>>> print(qq)
content="summary_large_image" />
<meta name="twitter:label1" content="Примерное время для чтения">
<meta name="twitter:data1" content="1 минута">
<script type="application/ld+json" class="yoast-schema-graph">{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://streetclimate.ru/#organization","name":"\u0421\u0442\u0440\u0438\u0442-\u041a\u043b\u0438\u043c\u0430\u0442","url":"https://какой-то сайт.ru/","sameAs":[],"logo":{"@type":"ImageObject","@id":"https://какой-то сайт.ru/#logo","inLanguage":"ru-RU","url":"https://какой-то сайт.ru/wp-content/uploads/2018/12/3_White_logo_on_color1_269x67.png","width":269,"height":67,"caption":"\u0421\u0442\u0440\u0438\u0442-\u041a\u043b\u0438\u043c\u0430\u0442"},"image":{"@id":"https://какой-то сайт.ru/#logo"}},{"@type":"WebSite","@id":"https://какой-то сайт.ru/#website","url":"https://какой-то сайт.ru/","name":"\u0421\u0442\u0440\u0438\u0442-\u041a\u043b\u0438\u043c\u0430\u0442","description":"\u041f\u0440\u043e\u0434\u0430\u0436\u0430, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0434\u0438\u0446\u0438\u043e\u043d\u0435\u0440\u043e\u0432, \u0441\u043f\u043b\u0438\u0442-\u0441\u0438\u0441\u0442\u0435\u043c \u0438 \u0442\u0435\u043f\u043b\u043e\u0432\u044b\u0445 \u0437\u0430\u0432\u0435\u0441 \u0432 \u0421\u041f\u0431 \u0438 \u041b\u0435\u043d\u0438\u043d\u0433\u0440\u0430\u0434\u0441\u043a\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438.",
>>>
"\u0421\u0442\u0440\u0438\u0442-\u041a\u043b\u0438\u043c\u0430\u0442"отлично раскодируется в JSON:
Стрит-Климат
'{"hello": "\\u043f\\u0440\\u0438\\u0432\\u0435\\u0442"}'
s = json.dumps(d, ensure_ascii=True)
print(s)
import json, requests
URL = 'https://api.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
def get_api_data(url, params=''):
r = requests.get(url, params='okhttp/2.5.0')
if r.status_code == 200:
return r.text
else:
print('Ошибка загрузки данных!')
exit(1)
api_data = get_api_data(URL)
api_json = json.loads(api_data)
print(api_json)
r: list[object] = wcapi.get("products", params={'per_page': 1, 'status': 'publish'}).json()