简单的 XML 加载文件不起作用 - Indeed.com api
当我的结果为空时,我正在使用 Indeed api 来回填我的职位发布。我不熟悉 api,但根据我的参数获取要加载的 url 时遇到一些困难。
<?php
$publisher = "############";
$sort = "relevance"; ## Sort by "relevance" or "date"
$radius = "50"; ## Distance from search location
$st = ""; ## Site type (default blank- can set to "jobsite" or "employer")
$jt = ""; ## Job type (default blank- can set to fulltime, parttime, contract, internship, or temporary)
$start_number = 0; ## Start search results at this number (used for pagination)
$limit = "10"; ## Number of results per page
$fromage = ""; ## Number of days to search back (default blank = 30)
$highlght = "1"; ## Bold the keyword search terms in results (set to 0 for no bold)
$filter = "1"; ## Filters out duplicate results (set to 0 for no filter)
$latlong = "1"; ## If latlong=1, returns latitude and longitude information for each result
$co = "us"; ## Country to search jobs in
$chnl = ""; ## API Channel request. Leave blank for none
$query = "web analytics";
$location = "55403";
$highlight = "1";
$userip = $_SERVER['REMOTE_ADDR']; ## IP address of user
$useragent = $_SERVER['HTTP_USER_AGENT']; ## User's browser type
$params =
array(
'publisher' => $publisher,
'q' => $query,
'l' => $location,
'sort' => $sort,
'radius' => $radius,
'st' => $st,
'jt' => $jt,
'start' => $start_number,
'limit' => $limit,
'fromage' => $fromage,
'filter' => $filter,
'latlong' => $latlong,
'co' => $co,
'chnl' => $chnl,
'userip' => $userip,
'useragent' => $useragent,
);
$url = 'http://api.indeed.com/ads/apisearch'.'?'.http_build_query($params,'', '&');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
$result = curl_exec($ch);
curl_close($ch);
$xml = (simplexml_load_file($url));
$xmlobj = $xml;
foreach ($xmlobj->results->result as $job) {
echo sprintf("%s<br>\n%s<br><br>\n\n", (string)$job->jobtitle,
(string)$job->snippet); }
?>
有人知道为什么 URL 无法加载吗?我修复了 q= 问题,但它仍然无法加载。
I am using the indeed api to backfill my job postings when my results is null. I am not familiar with the api but i am having some difficulty getting the url to load based on my parameters.
<?php
$publisher = "############";
$sort = "relevance"; ## Sort by "relevance" or "date"
$radius = "50"; ## Distance from search location
$st = ""; ## Site type (default blank- can set to "jobsite" or "employer")
$jt = ""; ## Job type (default blank- can set to fulltime, parttime, contract, internship, or temporary)
$start_number = 0; ## Start search results at this number (used for pagination)
$limit = "10"; ## Number of results per page
$fromage = ""; ## Number of days to search back (default blank = 30)
$highlght = "1"; ## Bold the keyword search terms in results (set to 0 for no bold)
$filter = "1"; ## Filters out duplicate results (set to 0 for no filter)
$latlong = "1"; ## If latlong=1, returns latitude and longitude information for each result
$co = "us"; ## Country to search jobs in
$chnl = ""; ## API Channel request. Leave blank for none
$query = "web analytics";
$location = "55403";
$highlight = "1";
$userip = $_SERVER['REMOTE_ADDR']; ## IP address of user
$useragent = $_SERVER['HTTP_USER_AGENT']; ## User's browser type
$params =
array(
'publisher' => $publisher,
'q' => $query,
'l' => $location,
'sort' => $sort,
'radius' => $radius,
'st' => $st,
'jt' => $jt,
'start' => $start_number,
'limit' => $limit,
'fromage' => $fromage,
'filter' => $filter,
'latlong' => $latlong,
'co' => $co,
'chnl' => $chnl,
'userip' => $userip,
'useragent' => $useragent,
);
$url = 'http://api.indeed.com/ads/apisearch'.'?'.http_build_query($params,'', '&');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
$result = curl_exec($ch);
curl_close($ch);
$xml = (simplexml_load_file($url));
$xmlobj = $xml;
foreach ($xmlobj->results->result as $job) {
echo sprintf("%s<br>\n%s<br><br>\n\n", (string)$job->jobtitle,
(string)$job->snippet); }
?>
Anyone have any idea why the URL is not loading? I fixed the q= issue, but it still does not load.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您将加载同一个文档两次。首先使用 cURL(不必要),然后使用 SimpleXML。从该脚本中删除了与 curl 相关的所有内容,您不需要它。
其次,文档加载正确,但不包含任何结果,因为发布者编号 ############ 显然是无效的。请清理您的脚本并提供您尝试加载的文档示例。
First off, you're loading the same document twice. First with cURL (needlessly) then with SimpleXML. Removed everything related to curl from that script, you don't need it.
Secondly, the document loads correctly, but it doesn't contain any results because the publisher number ############ is, obviously, invalid. Please clean up your script and provide a sample of the document you're trying to load.