API Indeed.com xml feed 上的分页每页 25 个结果,如何分页? [英] Pagination on the API Indeed.com xml feed 25 results per page, How to Paginate?

查看:20
本文介绍了API Indeed.com xml feed 上的分页每页 25 个结果,如何分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的网站上设置了 Indeed.com xml 提要.他们的 API 只允许每个查询 25 个结果.如果结果超过 25 个,如何对结果进行分页?

我在网上的任何地方都没有找到令人满意或足够彻底的答案.我已经为此搜索了数周.

这是我的代码:

PHP:

//Indeed.com API URL 参数$url = 'http://api.indeed.com/ads/apisearch'.'?';$publisher = 'xxxxxxxxxxxxxxxxxx';$q = $query;$位置 = '';if (isset($_POST['location'])) {$location = $_POST['location'];} 别的 {$geo = geoCheckIP($_SERVER['REMOTE_ADDR']);if (isset($geo) && ($geo != "not found, not found")) {$location = $geo;}}$sort = '日期';$radius = '20';$st = '';$jt = '';$start = '0';$limit = '25';$fromage = '';$highlight = '0';$过滤器 = '1';$latlong = '0';$co = '我们';$chnl = '';$userip = $_SERVER['REMOTE_ADDR'];$useragent = isset($_SERVER['HTTP_USER_AGENT']) ?($_SERVER['HTTP_USER_AGENT']) : '未知';$v = '2';$xml = simplexml_load_file($url."publisher=".$publisher."&q=".$q."&l=".$location."&sort=".$sort."&radius=".$radius."&st=".$st."&jt=".$jt."&start=".$start."&limit=".$limit."&fromage=".$fromage."&highlight=".$highlight."&filter=".$filter."&latlong=".$latlong."&co=".$co."&chnl=".$chnl."&userip=".$userip."&useragent=".$useragent."&v=".$v);

HTML 正文

 

<h1><?php echo $xml->totalresults ."".$jobroll_title ."靠近 " .$location ?></h1><!-- 开始确实的有序列表--><ol class="jobs"><?phpforeach($xml->results->result as $result) { ?><li class="job <?php echo (++$liBgColor%2 ? 'odd' : 'even'); ?>"><div class="title_wrapper"><div id="jobtitle"><strong><a onmousedown="<?php echo $result->onmousedown;?>"rel="nofollow" href="<?php echo $result->url;?>"target="_blank"><?php echo $result->jobtitle;?></a></strong></div><div id="company"><?php echo $result->company;?></div>

<div id="代码片段"><?php $result->snippet = str_replace(" ", ".", $result->snippet);echo $result->snippet;?>

<div id="location"><strong>位置:</strong><?php echo $result->formattedLocationFull;?></div><div id="date"><span class="posted <?php echo (++$locationBgColor%2 ? 'even' : 'odd'); ?>">Posted <?phpecho $result->formattedRelativeTime;?></span></div><div id="details-2"><strong><a onmousedown="<?php echo $result->onmousedown;?>"rel="nofollow" href="<?php echo $result->url;?>"target="_blank">详情</a></strong></div><?php } ?></ol><!-- 结束确实的有序列表--><!-- 这是分页显示的地方--><div class="pagenumber"><?php echo "Page Number" ."<a href=\"" . (rtrim(dirname($_SERVER['PHP_SELF']), '/')) . "\">".$xml->pageNumber .</a>"?></div>

这就是它的工作原理.用户到达网页,然后页面加载基于用户位置的作业结果.如果找到的邮政编码结果少于 25 个,则没有问题,不需要分页.

但是如果 xml 提要的结果超过 25 个,它将显示 25 个,仅此而已.如果我想显示其余部分,我必须分页.这就是我需要帮助的地方.

这是他们的 API 网址的工作原理.

http://api.indeed.com/ads/apisearch?publisher=xxxxxxxxxxxxxxx&q=java&l=austin%2C+tx&sort=&radius=&st=&jt=&start=0&limit=25&fromage=&filter=&latlong=1&co=us&chnl=&userip=1.2.3.4&useragent=Mozilla/%2F4.0%28Firefox%29&v=2

&start=0&limit=25的部分是如何根据xml的页码显示结果.

例如:&start=0&limit=25 将是显示 25 个结果的第 0 页,&start=25&limit=25 将是页面1 显示接下来的 25 个结果,&start=50&limit=25 将是显示剩余 25 个结果的第 2 页.此示例基于 xml 提要中是否总共有 75 个结果.

并且在我上面的 //Indeed.com API URL 参数 中,我将它设置为从第 0 页开始并限制为 25.他们不允许超过 25 的限制.如果设置得更高,则默认为 25.

 $start = '0';$limit = '25';

我需要一些帮助来实现一种使用上面我当前的 PHP 代码进行分页的方法.如何添加 PHP 代码中的内容?

解决方案

has_more 如果xml中有25个结果,函数返回true

$start = 0;做 {$xml = simplexml_load_file(...$start...);//处理 $xml$开始 += 25;} while(has_more($xml));

I have set up the Indeed.com xml feed on my site. Their API only allows 25 results per query. How can I paginate the results if there are more than 25?

I have not found a satisfactory or thorough enough answer anywhere online. I've searched for weeks on this.

Here is what I have in my code:

PHP:

        // Indeed.com API URL parameters
    $url = 'http://api.indeed.com/ads/apisearch'.'?';
    $publisher = 'xxxxxxxxxxxxxxxx';
    $q = $query;

    $location = '';
    if (isset($_POST['location'])) {
        $location = $_POST['location'];
    } else {
        $geo = geoCheckIP($_SERVER['REMOTE_ADDR']);
        if (isset($geo) && ($geo != "not found, not found")) {
            $location = $geo;
        }
    }
    $sort = 'date';
    $radius = '20';
    $st = '';
    $jt = '';
    $start = '0';
    $limit = '25';
    $fromage = '';
    $highlight = '0';
    $filter = '1';
    $latlong = '0';
    $co = 'us';
    $chnl = '';
    $userip = $_SERVER['REMOTE_ADDR'];
    $useragent = isset($_SERVER['HTTP_USER_AGENT']) ? ($_SERVER['HTTP_USER_AGENT']) : 'unknown';
    $v = '2';
    $xml = simplexml_load_file($url."publisher=".$publisher."&q=".$q."&l=".$location."&sort=".$sort."&radius=".$radius."&st=".$st."&jt=".$jt."&start=".$start."&limit=".$limit."&fromage=".$fromage."&highlight=".$highlight."&filter=".$filter."&latlong=".$latlong."&co=".$co."&chnl=".$chnl."&userip=".$userip."&useragent=".$useragent."&v=".$v);

HTML BODY

    <div class="paradiv">
      <h1><?php echo $xml->totalresults . " " . $jobroll_title . " Near " . $location ?></h1>
      <!-- BEGIN INDEED ORDERED LIST-->
      <ol class="jobs">
        <?php

    foreach($xml->results->result as $result) { ?>
        <li class="job <?php echo (++$liBgColor%2 ? 'odd' : 'even'); ?>">
          <div class="title_wrapper">
            <div id="jobtitle"><strong><a onmousedown="<?php echo $result->onmousedown;?>" rel="nofollow" href="<?php echo $result->url;?>" target="_blank"><?php echo $result->jobtitle;?></a></strong></div>
            <div id="company"><?php echo $result->company;?></div>
          </div>
          <div id="snippet">
            <?php $result->snippet = str_replace("  ", ". ", $result->snippet); echo $result->snippet;?>
          </div>
          <div id="location"><strong>Location:</strong> <?php echo $result->formattedLocationFull;?></div>
          <div id="date"><span class="posted <?php echo (++$locationBgColor%2 ? 'even' : 'odd'); ?>">Posted <?php echo $result->formattedRelativeTime;?></span></div>
          <div id="details-2"><strong><a onmousedown="<?php echo $result->onmousedown;?>" rel="nofollow" href="<?php echo $result->url;?>" target="_blank">Details</a></strong></div>
        </li>
        <?php } ?>
      </ol>
      <!-- END INDEED ORDERED LIST -->

      <!-- THIS IS WHERE THE PAGINATION WILL DISPLAY -->
      <div class="pagenumber"><?php echo "Page Number " . "<a href=\"" . (rtrim(dirname($_SERVER['PHP_SELF']), '/')) . "\">" . $xml->pageNumber . "</a>" ?></div>
    </div>

This is how it works. A user arrives on the web page, then the page loads with the job results based on the users location. If less than 25 results are found for their zip code then there is no problem and pagination isn't needed.

But if the xml feed has more than 25 results, it will show 25 and that's it. If I want to display the rest, I have to paginate. This is what I need help with.

Here is how their API url works.

http://api.indeed.com/ads/apisearch?publisher=xxxxxxxxxxxxxxx&q=java&l=austin%2C+tx&sort=&radius=&st=&jt=&start=0&limit=25&fromage=&filter=&latlong=1&co=us&chnl=&userip=1.2.3.4&useragent=Mozilla/%2F4.0%28Firefox%29&v=2

The part that says &start=0&limit=25 is how to display the results based on page number of the xml.

So for example: &start=0&limit=25 would be page 0 showing 25 results, &start=25&limit=25 would be page 1 showing the next 25 results and &start=50&limit=25 would be page 2 showing the remaining 25 results. This example is based on if there are a total of 75 results in the xml feed.

And in my // Indeed.com API URL parameters above I have it set to start on page 0 and limit to 25. They do not allow beyond 25 in limit. If set higher it will default to 25.

    $start = '0';
    $limit = '25';

I need some help on implementing a way to paginate using my current PHP code above. How can I add on to what I have in my PHP code?

解决方案

has_more function returns true if there are 25 results in the xml

$start = 0;
do {
  $xml = simplexml_load_file(...$start...);
  // process $xml
  $start += 25;
} while(has_more($xml));

这篇关于API Indeed.com xml feed 上的分页每页 25 个结果,如何分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆