【问题标题】:Scrape Renewal Pricing From Go Daddy' pricing list从 Go Daddy 的定价表中刮取更新定价
【发布时间】:2013-10-01 09:20:23
【问题描述】:

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

我想为流行域的通用 TLD 争取续订价格。

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

【问题讨论】:

    标签: php regex web-scraping


    【解决方案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* | 
    ---
    

    【讨论】:

    • 如何解析 JSON?我是否会提取 html 部分,然后运行 ​​HTML 解析器以从表中获取续订价格?
    • 哦,我没注意到它包含 html 代码...但这就是想法,您获取 html 代码然后使用诸如 Simple HTML DOM Parser 之类的一些 dom 解析器对其进行解析...我会发布稍后再举个例子……
    • @user1512405,添加示例...您可以参考Simple HTML DOM Parser's documentation了解更多详情
    猜你喜欢
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-16
    • 1970-01-01
    相关资源
    最近更新 更多