如何使用 python 请求获取网站的服务器信息?
How to get the server info of a website using python requests?
我想做一个网络爬虫来统计保加利亚站点中最受欢迎的服务器软件,例如Apache,nginx等。这是我想出的:
import requests
r = requests.get('http://start.bg')
print(r.headers)
其中return以下:
{'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']
就可以得到这个结果。我在几个保加利亚网站上尝试过,它们都有 Server 键。
但是,当我请求 header 更复杂的网站时,例如 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
我不确定它们的意思,但它值不是像 Apache.
这样的服务器名称
所以我想我必须发送另一个请求来产生所需的服务器信息,或者他们可能有自己特定的服务器软件(这对于 facebook[=40= 来说似乎是合理的) ]).
我还尝试了其他 .com 网站,例如 https://spotify.com,它确实有一个 ['Server']
键。
那么有没有办法找到有关 Facebook 和 Tesla Motors 使用的服务器的信息?
这与 python 无关,由于安全隐患,大多数配置良好的 Web 服务器不会 return "server" http header 中的信息。
任何理智的开发人员都不会想让您知道他们是 运行 xxx 产品的未打补丁版本。
我想做一个网络爬虫来统计保加利亚站点中最受欢迎的服务器软件,例如Apache,nginx等。这是我想出的:
import requests
r = requests.get('http://start.bg')
print(r.headers)
其中return以下:
{'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']
就可以得到这个结果。我在几个保加利亚网站上尝试过,它们都有 Server 键。
但是,当我请求 header 更复杂的网站时,例如 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
我不确定它们的意思,但它值不是像 Apache.
所以我想我必须发送另一个请求来产生所需的服务器信息,或者他们可能有自己特定的服务器软件(这对于 facebook[=40= 来说似乎是合理的) ]).
我还尝试了其他 .com 网站,例如 https://spotify.com,它确实有一个 ['Server']
键。
那么有没有办法找到有关 Facebook 和 Tesla Motors 使用的服务器的信息?
这与 python 无关,由于安全隐患,大多数配置良好的 Web 服务器不会 return "server" http header 中的信息。
任何理智的开发人员都不会想让您知道他们是 运行 xxx 产品的未打补丁版本。