gpt4 book ai didi

python - 使用 Python 抓取 HTTP 横幅

转载 作者:太空宇宙 更新时间:2023-11-04 11:03:48 26 4
gpt4 key购买 nike

我有兴趣制作一个 HTTP 横幅抓取器,但是当我连接到端口 80 上的服务器并发送一些东西(例如“HEAD/HTTP/1.1”)时,recv 不会像我这样做时那样返回任何东西给我让我们说 netcat..

我该怎么做?

谢谢!

最佳答案

尝试使用 urllib2 module .

>>> 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 header :

>>> 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=
>>>

关于python - 使用 Python 抓取 HTTP 横幅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3076263/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com