python 基础教程第二版 14章少数几个网络设计模块
网络编程socket 小型服务器
import socket
s = socket.socket()
host = socket.gethostname()
port = 1234
s.bind((host, port))
while True:
client, addr = s.accept()
print('Connection from', addr)
client.send('Thanks for connection')
client.close()
import socket
s = socket.socket()
host = socket.gethostname()
port = 1234
s.connect((host, port))
print s.recv(1024)
尝试使用 urllib 解析网页时候报错没有 urlopen
百度之发现 python3.x 调整了 urllib 库
import urllib.request
webpage = urllib.request.urlopen("https://www.baidu.com")
import re
text = webpage.read()
print text