我想打网络爬虫作出关于保加利亚的网站,比如Apache,Nginx的,等这当中最流行的服务器软件的统计是什么,我想出了:如何使用python请求获取网站的服务器信息?
import requests
r = requests.get('http://start.bg')
print(r.headers)
哪些返回以下内容:
{'Debug': 'unk',
'Content-Type': 'text/html; charset=utf-8',
'X-Powered-By': 'PHP/5.3.3',
'Content-Length': '29761',
'Connection': 'close',
'Set-Cookie': 'fbnr=1; expires=Sat, 13-Feb-2016 22:00:01 GMT; path=/; domain=.start.bg',
'Date': 'Sat, 13 Feb 2016 13:43:50 GMT',
'Vary': 'Accept-Encoding',
'Server': 'Apache/2.2.15 (CentOS)',
'Content-Encoding': 'gzip'}
在这里你可以很容易地看到,它运行在Apache/2.2.15,你可以通过简单地说r.headers['Server']
得到这样的结果。我尝试了几个保加利亚网站,他们都拥有服务器密钥。
然而,当我要求更复杂的网站的标题,如www.teslamotors.com,我得到以下信息:
{'Content-Type': 'text/html; charset=utf-8',
'X-Cache-Hits': '9',
'Cache-Control': 'max-age=0, no-cache, no-store',
'X-Content-Type-Options': 'nosniff',
'Connection': 'keep-alive',
'X-Varnish-Server': 'sjc04p1wwwvr11.sjc05.teslamotors.com',
'Content-Language': 'en',
'Pragma': 'no-cache',
'Last-Modified': 'Sat, 13 Feb 2016 13:07:50 GMT',
'X-Server': 'web03a',
'Expires': 'Sat, 13 Feb 2016 13:37:55 GMT',
'Content-Length': '10290',
'Date': 'Sat, 13 Feb 2016 13:37:55 GMT',
'Vary': 'Accept-Encoding',
'ETag': '"1455368870-1"',
'X-Frame-Options': 'SAMEORIGIN',
'Accept-Ranges': 'bytes',
'Content-Encoding': 'gzip'}
正如你可以看到没有任何['Server']
在本词典键(虽然有X-Server
和X-Varnish-Server
这我不知道他们是什么意思,但它的价值不是服务器名称,如阿帕奇。
所以我想一定有另一个请求我可能会发送这将产生所需的服务器信息,或者他们可能有他们自己的特定服务器软件(这听起来似乎facebook)。 我也尝试其他.com网站,如它确实有一个['Server']
键。
那么有没有办法找到有关Facebook和特斯拉汽车使用的服务器的信息?
Web服务器可能会或可能不会返回服务器标头。不要指望它。看到这个问题:http://stackoverflow.com/questions/4726515/what-http-response-headers-are-required – Selcuk
好吧,有道理。 :) –