[英]Parse apple-touch-icon from mobile websites
With a given url like www.example.com i want to extract the apple touch icon by eg searching the dom for this attribute: 对于给定的网址,例如www.example.com,我想通过例如搜索dom的以下属性来提取苹果触摸图标:
<link rel="apple-touch-icon" href="touch-icon-iphone.png">
The Problem is that example.com doesn't provide this tag on the normal website, just on the mobile m.example.com website. 问题在于example.com在普通网站上没有提供此标签,仅在移动m.example.com网站上提供了此标签。 I think they use server side device detection and add this tag only on mobile devices.
我认为他们使用服务器端设备检测,并且仅在移动设备上添加此标签。 Any idea on how i could get this icons on such websites?
关于如何在此类网站上获取此图标的任何想法吗?
If example.com
has a m.example.com
mobile version, they are probably redirecting mobile phone users using User Agent sniffing . 如果
example.com
具有m.example.com
移动版本,则他们可能正在使用User Agent Sniffing重定向手机用户。
The website's server basically looks at your request's User-Agent
HTTP header and matches it against a set of values to detect mobile browsers. 该网站的服务器基本上会查看您请求的
User-Agent
HTTP标头,并将其与一组值进行匹配以检测移动浏览器。 Here is an example of how it is done in Apache: 这是一个如何在Apache中完成的示例:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{HTTP_USER_AGENT} (.*)iPhone(.*) [NC,OR]
RewriteRule ^ http://m.example.com [L,QSA]
The good news is you can fool the server into serving you m.example.com
by setting the header yourself. 好消息是,您可以自己设置标题,从而使服务器欺骗您为
m.example.com
服务。 Here is an example with curl : 这是curl的示例:
curl facebook.com
curl facebook.com -L -A "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5"
The first one will retrieve the HTML for facebook.com, the second one sets the User-Agent header to the iPhone's value. 第一个将检索facebook.com的HTML,第二个将User-Agent标头设置为iPhone的值。 Note that we must use the -L option in order for curl to follow the redirect from
facebook.com
to m.facebook.com
. 请注意,为了使curl遵循从
facebook.com
到m.facebook.com
的重定向,必须使用-L选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.