在Python中,“urllib库”和“urllib库”有什么区别?和“套接字库”?
我正在学习网络编程基础知识,我的作业中有一个问题我不知道如何回答。
Python 中的“urllib 库”与“socket 库”有何不同? 我怎样才能解释清楚呢?
I'm learning network programming basics, and there is a question I don't know how to answer in my assignment.
How is 'urllib library' different from 'socket library' in Python?
How can I explain it clearly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
urllib
级别要高得多。socket
提供对许多不同类型套接字的低级访问,您可以使用它通过任何端口和协议进行通信。例如,您可以将其用于电子邮件、SSH、远程桌面等。您还可以将其用于侦听端口(用于服务器)。几乎所有 Python 网络库(包括 urllib)都以某种方式使用套接字。urllib 专门用于套接字的特定用途,即 HTTP(以及可选的 TLS)和 FTP 协议的客户端,通常(但不总是)使用端口 80、443 或 21。
urllib
is much higher level.socket
provides low-level access to many different kinds of sockets, which you can use to communicate over any port and protocol. For example, you could use it for email, SSH, remote desktop, etc. You can also use it for to listen on a port (for a server). Almost all Python networking libraries, includingurllib
, usesocket
somehow.urllib
is specialized to particular uses of sockets, namely the client side of the HTTP (and optionally TLS) and FTP protocols, typically (but not always) using ports 80, 443, or 21.在我的基本思维中,urllib 需要更少的代码行并且更一致地附加到服务器。事实上,socket 可能会花费您更多的时间来访问互联网,并且需要您更多的代码来处理您的代码。
In my basic mindset, urllib require you less code line and more consistent to attach to the server. In fact, socket may take you much more time to access the internet and require you more code to process through your code.