卷曲:HTTP 415不支持的媒体类型

时间:2018-02-21 14:14:03

标签: php curl web-scraping

下午好,

我想使用API​​从这个网站获取数据,尤其是PHP中的ids部分(目标),但我得到以下错误:HTTP 415不支持的媒体类型。

我目前使用的代码是(ИванЯсинский):

function getContentCurl($url)
{
    $ch =  curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; 
rv:25.0) Gecko/20100101 Firefox/25.0');
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch, CURLOPT_TIMEOUT, 3);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");

    return $result = curl_exec($ch);

}



$url = "https://cadres.apec.fr/cms/webservices/rechercheOffre/ids";
$content =  getContentCurl($url);

var_dump($content);

有没有人有任何想法克服这个问题?谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

您错过了帖子数据。我不确定您的确切查询,但此代码中有一个示例查询:

 string(4083) "{"totalCount":78073,"offreFilters":[{"offreFiltering":"CONTRACT_TYPE_FILTERING","offreFilterItems":[{"key":101888,"count":69550},{"key":20053,"count":120},{"key":101930,"count":2144},{"key":101887,"count":6259}]},{"offreFiltering":"CONTRACT_DURATION_FILTERING","offreFilterItems":[{"key":143691,"count":4981},{"key":143692,"count":2562},{"key":143693,"count":976}]},{"offreFiltering":"COMPANY_TYPE_FILTERING","offreFilterItems":[{"key":143684,"count":35345},{"key":143685,"count":18112},{"key":143686,"count":13180},{"key":143687,"count":11436}]},{"offreFiltering":"POSITION_STATUS_FILTERING","offreFilterItems":[{"key":143688,"count":65264},{"key":143689,"count":1629},{"key":143690,"count":11180}]},{"offreFiltering":"EXPERIENCE_FILTERING","offreFilterItems":[{"key":101881,"count":36267},{"key":20043,"count":45182},{"key":20044,"count":11797},{"key":20045,"count":11317}]},{"offreFiltering":"GEOLOCALISABLE_FILTERING","offreFilterItems":[{"key":0,"count":6088},{"key":1,"count":71985}]},{"offreFiltering":"JOB_CODE_FILTERING","offreFilterItems":[{"key":101829,"count":1360},{"key":101828,"count":19240},{"key":101831,"count":11451},{"key":101830,"count":1336},{"key":101833,"count":17141},{"key":101832,"count":10470},{"key":101835,"count":4190},{"key":101834,"count":7131},{"key":101837,"count":11231},{"key":101836,"count":1463}]},{"offreFiltering":"LOCATION_FILTERING","offreFilterItems":[{"key":102099,"count":731},{"key":99700,"count":411},{"key":799,"count":77342}]},{"offreFiltering":"NAF_CODE_FILTERING","offreFilterItems":[{"key":101761,"count":1083},{"key":101760,"count":3773},{"key":101763,"count":3607},{"key":101762,"count":11726},{"key":101765,"count":385},{"key":101764,"count":2123},{"key":101767,"count":1134},{"key":101766,"count":1757},{"key":101769,"count":621},{"key":101768,"count":169},{"key":101771,"count":332},{"key":101770,"count":1241},{"key":101773,"count":9665},{"key":101772,"count":9572},{"key":101775,"count":695},{"key":101774,"count":2410},{"key":101777,"count":1597},{"key":101776,"count":1292},{"key":101779,"count":1308},{"key":101778,"count":336},{"key":101780,"count":158},{"key":101753,"count":11418},{"key":101752,"count":1529},{"key":101755,"count":1026},{"key":101754,"count":2418},{"key":101757,"count":4055},{"key":101756,"count":1413},{"key":101759,"count":959},{"key":101758,"count":271}]},{"offreFiltering":"NIVEAU_ETUDE"},{"offreFiltering":"DUREE_STAGE","offreFilterItems":[{"key":599765,"count":381},{"key":599766,"count":233},{"key":599767,"count":710},{"key":599768,"count":441},{"key":599769,"count":280},{"key":599770,"count":2936},{"key":599771,"count":3538}]},{"offreFiltering":"DATE_PRISE_POSTE","offreFilterItems":[{"key":599777,"count":75435},{"key":599778,"count":2209},{"key":599779,"count":429}]},{"offreFiltering":"PERIOD_FILTERING","offreFilterItems":[{"key":101850,"count":11054},{"key":101851,"count":32259},{"key":101852,"count":78073},{"key":101853,"count":78073}]},{"offreFiltering":"WAGE_FILTERING","offreFilterItems":[{"key":597179,"count":7147},{"key":599738,"count":38996},{"key":101840,"count":56141},{"key":101841,"count":25697},{"key":101842,"count":6213},{"key":101843,"count":1408}]}],"resultats":[{"@uriOffre":"offre?numeroOffre=163035045W"},{"@uriOffre":"offre?numeroOffre=163035043W"},{"@uriOffre":"offre?numeroOffre=163035044W"},{"@uriOffre":"offre?numeroOffre=162918884W"},{"@uriOffre":"offre?numeroOffre=162913997W"},{"@uriOffre":"offre?numeroOffre=163035042W"},{"@uriOffre":"offre?numeroOffre=162930465W"},{"@uriOffre":"offre?numeroOffre=162926697W"},{"@uriOffre":"offre?numeroOffre=163035041W"},{"@uriOffre":"offre?numeroOffre=163035040W"},{"@uriOffre":"offre?numeroOffre=163035039W"},{"@uriOffre":"offre?numeroOffre=163035036W"},{"@uriOffre":"offre?numeroOffre=163035032W"},{"@uriOffre":"offre?numeroOffre=163035031W"},{"@uriOffre":"offre?numeroOffre=163035030W"},{"@uriOffre":"offre?numeroOffre=163035029W"},{"@uriOffre":"offre?numeroOffre=163035027W"},{"@uriOffre":"offre?numeroOffre=163035026W"},{"@uriOffre":"offre?numeroOffre=163035022W"},{"@uriOffre":"offre?numeroOffre=163035020W"}]}"

输出:

<property>
 <name>take.screenshot</name>
 <value>true</value>
 <description>
  Boolean property determining whether the protocol-htmlunit
  WebDriver should capture a screenshot of the URL. If set to
  true remember to define the 'screenshot.location'
  property as this determines the location screenshots should be
  persisted to on HDFS. If that property is not set, screenshots
  are simply discarded.
 </description>
</property>

<property>
 <name>screenshot.location</name>
 <value>/home/user/nutch-1.14/screenshot</value>
 <description>
  The location on disk where a URL screenshot should be saved
  to if the 'take.screenshot' property is set to true.
  By default this is null, in this case screenshots held in memory
  are simply discarded.
 </description>
</property>