从Go Daddy的定价清单中获取续订定价

时间:2013-10-01 09:20:24

标签: php regex web-scraping

https://www.godaddy.com/domains/popups/chart.aspx

我希望为流行域名提取通用顶级域名的续订价格。

我正在寻找源代码,但没有看到价格数字......这些变量在哪里找到?

1 个答案:

答案 0 :(得分:1)

价格是在页面加载后动态生成的......这是默认表格的价格链接

https://www.godaddy.com/domains/controls/jsoncontent/generalpricing.aspx?tab=general&widthreduction=160&hidelinks=true&TargetDivId=tabgj_new&regt=new&_=1380620289373

它返回一个可以使用json_decode()

解析的json文件

要查看与页面交互时动态变化的内容,在Chrome中,从顶部启动developper tools然后Network标签,从底部启动XHR标签...

在该标签中,您将看到网站与服务器之间的所有动态通信

编辑:

这是一个有效的例子:

// includes Simple HTML DOM Parser
require_once "php/lib/simplehtmldom_1_5/simple_html_dom.php";

$url = "https://www.godaddy.com/domains/controls/jsoncontent/generalpricing.aspx?tab=general&widthreduction=160&hidelinks=true&TargetDivId=tabgj_new&regt=new&_=1380620289373";

// Download json file and converts it into a PHP variable
$jsonData = json_decode(file_get_contents($url));

// get html data from the json object
$htmlData = $jsonData->Html;


/*
 * Parse the HTML DOM using Simple HTML DOM Parser
 */

//Create a DOM object
$html = new simple_html_dom();
// Load HTML from a string
$html->load($htmlData);

// Print results
foreach($html->find("table tr") as $index => $row) {

    switch ($index) {

        case '0':   // Print table header
            foreach($row->find("th") as $col) {
                echo $col->plaintext;
                echo " | ";
            }
            echo "<br/>---<br/>";
            break;

        default:    // Print all rows
            foreach($row->find("td") as $col) {
                echo $col->plaintext;
                echo " | ";
            }
            echo "<br/>---<br/>";
            break;
    }
}


OUTPUT:
-------
Per year pricing | 1 year | 2 years | 3 years | 5 years | 10 years | 
---
.COM | $12.99* $14.99* | $13.99* $14.99* | $14.33* $14.99* | $14.59* $14.99* | $14.79* $14.99* | 
---
.CO | $12.99 $29.99 | $21.49 $29.99 | $24.33 $29.99 | $26.59 $29.99 | -- | 
---
.INFO | $2.99* $14.99* | $8.99* $14.99* | $10.99* $14.99* | $12.59* $14.99* | $13.79* $14.99* | 
---
.ORG | $9.99* $17.99* | $13.99* $17.99* | $15.33* $17.99* | $16.39* $17.99* | $17.19* $17.99* | 
---
.NET | $9.99* $16.99* | $13.49* $16.99* | $14.66* $16.99* | $15.59* $16.99* | $16.29* $16.99* | 
---
.ME | $9.99 $19.99 | $14.99 $19.99 | $16.66 $19.99 | $17.99 $19.99 | $18.99 $19.99 | 
---
.MOBI | $9.99* $17.99* | $13.99* $17.99* | $15.33* $17.99* | $16.39* $17.99* | $17.19* $17.99* | 
---
.US | $3.99 $19.99 | $11.99 $19.99 | $14.66 $19.99 | $16.79 $19.99 | $18.39 $19.99 | 
---
.BIZ | $6.99* $16.99* | $11.99* $16.99* | $13.66* $16.99* | $14.99* $16.99* | $15.99* $16.99* | 
---
.CA | $12.99 | $12.99 | $12.99 | $12.99 | $12.99 | 
---
.CC | $19.99 | $19.99 | $19.99 | $19.99 | $19.99 | 
---
.LA | $39.99 | $39.99 | $39.99 | $39.99 | $39.99 | 
---
.TV | $39.99 | $39.99 | $39.99 | $39.99 | $39.99 | 
---
.WS | $15.99 | $15.99 | $15.99 | $15.99 | $15.99 | 
---
.ASIA | $19.99* | $19.99* | $19.99* | $19.99* | $19.99* | 
---
.XXX | $99.99* | $99.99* | $99.99* | $99.99* | $99.99* | 
---