【问题标题】:Post request returns 404发布请求返回 404
【发布时间】:2017-11-19 16:31:18
【问题描述】:

最后,我想在过去两天进行高级搜索时“抓取”以下网页。 https://launchstudio.bluetooth.com/Listings/Search

结果似乎是由调用 API 的 javascript 生成的

bt.apiUrl = 'https://platformapi.bluetooth.com/';
$.ajax({
    method: 'post',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    url:  bt.apiUrl +'api/platform/Listings/Search',
    data: JSON.stringify(this.searchCriteria),
    success: function (data) {
        if (data.length) {
            var listings = data
            console.log('listing count: ' + listings.length);
            this.listings = listings;
        }

    }.bind(this)

找到以下 API 文档: https://platformapi.bluetooth.com/Help/Api/POST-api-Platform-Listings-Search

但是,我的简单脚本返回 404

import requests
import json

payload ={
  'UserId': '',
  'MemberId': '',
  'SearchString': '',
  'SearchQualificationsAndDesigns': 1,
  'SearchDeclarationOnly': 1,
  'SearchEndProductList': 1,
  'SearchPRDProductList': 1,
  'SearchMyCompany': 1,
  'BQAApprovalStatusId': 9,
  'BQALockStatusId': 10,
  'ProductTypeId': 1,
  'SpecName': 1,
  'ListingDateEarliest': "2017-11-17T09:43:09.2031162-06:00",
  'ListingDateLatest': "2017-11-18T09:43:09.2031162-06:00",
  'Layers': [],
  'MaxResults': 11,
  'IncludeTestData': 1
}

url = 'https://platformapi.bluetooth.com/api/Platform/Listings/Search'
headers = {'Content-type': 'application/json', 'Accept': 'text/json'}
r = requests.post(url, data=json.dumps(payload), headers=headers)
print (r.status_code)

任何人都知道为什么?顺便说一句,使用 Python 3.5。

【问题讨论】:

    标签: python json http-post


    【解决方案1】:
    import requests
    import json
    
    payload = {
        "searchString":"bluetooth",
        "searchQualificationsAndDesigns":True,
        "searchDeclarationOnly":True,
        "searchEndProductList":False,
        "searchPRDProductList":True,
        "searchMyCompany":False,
        "productTypeId":0,
        "specName":0,
        "bqaApprovalStatusId":-1,
        "bqaLockStatusId":-1,
        "listingDateEarliest":"",
        "listingDateLatest":"",
        "userId":0,
        "memberId":None,
        "layers":[],
        "maxResults":5000
        }
    
    url = 'https://platformapi.bluetooth.com/api/Platform/Listings/Search'
    headers = {'Content-type': 'application/json; charset=utf-8', 'Accept': 'text/json'}
    r = requests.post(url, data=json.dumps(payload), headers=headers)
    print (r.status_code)
    #print r.json()
    

    结果:

    200
    

    【讨论】:

    • 你做了什么?
    猜你喜欢
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    • 2018-04-29
    • 2018-06-03
    • 1970-01-01
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多