是否有任何解决方案可以检查网页是否适合移动设备 (C#) [英] Is There Any Solution To Check a Webpage is Mobile Friendly (C#)

查看:67
本文介绍了是否有任何解决方案可以检查网页是否适合移动设备 (C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道由于大多数网站都使用响应式主题或移动友好,是否有任何解决方案可以以编程方式检查给定的 url 是否适合移动设备.

I was wondering since most of the websites use responsive themes or mobile friendly is there any solution to check whether a given url is mobile friendly or not programmatically.

谷歌(手册)中存在类似的解决方案 - https://www.google.co.uk/webmasters/tools/mobile-friendly/

Similar solution exist within google (manual) - https://www.google.co.uk/webmasters/tools/mobile-friendly/

你们对可能的解决方案有什么想法吗?

Do you guys have any ideas on possible solutions ?

推荐答案

以下使用此代码来自 GitHub

(1) 从 Google Developers Console

(2) 自定义以下php代码,或以编程方式生成.请注意,在第 19 行,您需要使用自己的 API 密钥并输入自己的 URL

(2) customise the following php code, or produce programatically. Note that at line 19 you'll need to use your own API key and enter your own URL

 <?php
    /**
     * @param $url
     * @param $apiKey
     * @return mixed
     */
    function isMobileReady($url, $apiKey)
    {
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => 'https://www.googleapis.com/pagespeedonline/v3beta1/mobileReady?key='.$apiKey.'&url='.$url.'&strategy=mobile',
        ));
        $resp = curl_exec($curl);
        curl_close($curl);
        return $resp;
    }
    //result as an array look for  ["pass"]=> bool(true) } or false
    $result = json_decode(isMobileReady('https://www.panchroma.ca/en/', 'AIzaSyDSrus1NcAIFXOWQjoAgwEOVChX_KEnhg_dummy_api_key'), true);
    var_dump($result);

(3) pagespeed 结果被转储到屏幕上,我认为移动友好测试结果最重要的信息靠近顶部.寻找

(3) the pagespeed results are dumped to the screen, I think the most important info for the mobile friendly test result is near the top. Look for

{ ["USABILITY"]=> array(2) { ["score"]=> int(98) ["pass"]=> bool(true) } }  

分数是您的 Google PageSpeed 分数 [0-100] 并且pass"布尔值为 true 或 false,true 相当于通过 移动友好测试

The score is your Google PageSpeed score [0-100] and the "pass" boolean is either true or false, true is equivalent to passing the Mobile Friendly Test

完全感谢作者

===

针对如何测试多个网址的问题,我有以下建议.
这是实时结果.

In response to a question of how to test multiple URLs, I have one suggestion below.
And here's the live result .

这会将大量内容转储到页面,搜索分数"以查看 3 个示例 URL 的移动友好测试结果

This dumps a lot of stuff to the page, search for 'score' to see the mobile-friendly test results for the 3 sample URLs

<?php
    /**
     * @param $url
     * @param $apiKey
     * @return mixed
     */
    function isMobileReady($url, $apiKey)
    {
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => 'https://www.googleapis.com/pagespeedonline/v3beta1/mobileReady?key='.$apiKey.'&url='.$url.'&strategy=mobile',
        ));
        $resp = curl_exec($curl);
        curl_close($curl);
        return $resp;
    }

    $websites = array( "https://www.panchroma.ca/en/", "https://www.google.ca","https://www.youtube.com" );
    foreach($websites as $website) { 

        $result = json_decode(isMobileReady($website, 'AIzaSyDSrus1NcAIFXOWQjoAgwEOVChX_KEnhg_dummy_api_key'), true);
        var_dump($result);
    }

?>

希望这会有所帮助!

这篇关于是否有任何解决方案可以检查网页是否适合移动设备 (C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆