JSON使用Python的困难';s请求库

JSON使用Python的困难';s请求库,python,json,python-requests,Python,Json,Python Requests,在尝试刮除产品时 import requests headers = { 'authority': 'www.producthunt.com', 'pragma': 'no-cache', 'cache-control': 'no-cache', 'upgrade-insecure-requests': '1', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/

在尝试刮除产品时

import requests

headers = {
    'authority': 'www.producthunt.com',
    'pragma': 'no-cache',
    'cache-control': 'no-cache',
    'upgrade-insecure-requests': '1',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'sec-fetch-site': 'none',
    'sec-fetch-mode': 'navigate',
    'sec-fetch-user': '?1',
    'sec-fetch-dest': 'document',
    'accept-language': 'en-US,en;q=0.9',
}

response = requests.get('https://www.producthunt.com/', headers=headers)
我发现返回的响应没有可转换为json的有效字符串。在尝试用response.text.replace()替换引号类型并用json.loads(re.sub(r'^jsonp\d+(|)\s+$,'',response.text))返回json后,我仍然收到相同的错误

错误:

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

想法?

问题与JSON无关

您请求的是网页,而不是JSON API

$ curl -sH 'Accept: application/json' https://www.producthunt.com/ | head -c 200
<!DOCTYPE html><html lang="en"><head><title>Product Hunt – The best new products in tech.</title><link rel="canonical" href="https://www.producthunt.com/"/><meta name="description" content="Product %
$curl-sH'Accept:application/json'https://www.producthunt.com/ |头部-c 200

Product Hunt–技术上最好的新产品。更改为
'Accept':'application/json'
标题可能会有所帮助。^您正在接受XHTML或图像作为响应。请注意:
producthunt.com
仅是HTML。。。没有神奇的方法可以将任何网页转换为JSONU不幸的是,我已经尝试过了:(向我们展示完整的错误回溯和引发错误的完整代码。还向我们展示返回的状态代码和响应body.hm的开头,所以稍微让我感到不舒服的是
data='${“operationName”:“主页”,“变量”:{“光标”:“NQ==”,“featured”:true,“includePromotedPost”:false,“visibleOnHomepage”:true,“IncludeDelayOut”:false},“查询”:“查询主页($cursor:String,$postCursor:String,$featured:Boolean\\u0021,$includePromotedPost:Boolean\\u0021,$visibleOnHomepage:Boolean\\u0021)}”响应=requests.get('https://www.producthunt.com/frontend/graphql“,headers=headers,data=data)
对于原始的头,只会给我一个错误“{”状态:400,“error':“Bad Request”}``我不确定,因为我不管理ProductHunt。我建议在python中使用GraphQL库,而不是使用请求