我想用Python写一行,但是我被卡住了。在
这是我的代码:
import urllib2
response = urllib2.urlopen('http://pythonforbeginners.com/')
info = response.info()
html = response.read()
# do something
response.close() # best practice to close the file
if "x" in str(info):
print str(info)
raw_input()
我只是想得到一条线来显示服务器的类型。在
我猜你的行是指http头中的一行。 您可以通过以下代码获取http头:
或者,您可以将信息转换为字符串并按\r\n拆分(http头由\r\n分隔),如下所示
^{pr2}$您真的需要将
info
视为字符串吗?如果没有,这应该很有效:相关问题 更多 >
编程相关推荐