python14——2day网络服务器

网络

小型服务器

import socket

s = socket.socket()
host = socket.gethostname() # 获取主机名
port = 1234
s.bind((host, port))
s.listen(1) # 监听给定的地址
while True:
c, addr = s.accept() # 等待下一个连接
print(‘got connection from’, addr)
c.send(‘thank you for connectong’) # 传输数据
c.close()

小型客户机

s = socket.socket()
host = socket.gethostname() # 获取主机名
port = 1234
s.connect((host, port))
print(s.recv(1024))


import urllib
import urllib.request
import re
from bs4 import BeautifulSoup

webage = urllib.request.urlopen(‘http://www.yznnw.com/files/article/html/1/1129/index.html’).read()
soup = BeautifulSoup(webage)
subtitle = soup.select(’#htmltimu’)[0].text
m = re.search(r’.*?章’, subtitle)
print(m)

猜你喜欢

转载自blog.csdn.net/qq_38501057/article/details/88427000