1

我对制作 HTTP Banner Grabber 很感兴趣,但是当我连接到端口 80 上的服务器并发送一些东西(例如“HEAD / HTTP/1.1”)时,recv 不会像我这样做时返回任何东西让我说网猫..

我该怎么办?

谢谢!

4

2 回答 2

2

您是否发送“\r\n\r\n”来指示请求结束?如果不是,服务器仍在等待请求的其余部分。

于 2010-06-19T16:32:04.073 回答
2

尝试使用urllib2模块

>>> data = urllib2.urlopen('http://www.example.com').read()
>>> print data
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
  <META http-equiv="Content-Type" content="text/html; charset=utf-8">
  <TITLE>Example Web Page</TITLE>
</HEAD> 
<body>  
<p>You have reached this web page by typing &quot;example.com&quot;,
&quot;example.net&quot;,
  or &quot;example.org&quot; into your web browser.</p>
<p>These domain names are reserved for use in documentation and are not available 
  for registration. See <a href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC 
  2606</a>, Section 3.</p>
</BODY>
</HTML>

>>>

询问示例,您可能会错过更多细节。要查看content-type标题:

>>> stream = urllib2.urlopen('http://www.example.com')
>>> stream.headers['content-type']
'text/html; charset=UTF-8'
>>> data = stream.read()
>>> print data[:100]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
  <META http-equiv=
>>>
于 2010-06-19T16:37:30.437 回答