困于心衡于虑而后作
今天的学习目标是:flask与爬虫互传数据_post方法
一、flask与爬虫互传数据_post方法
1.首先写爬虫模块
import urllib.request
url = "http://127.0.0.1:5000"
p = "广东"
c = "深圳"
n = "困于心衡于虑而后作"
p = urllib.parse.quote(p)
c = urllib.parse.quote(c)
n = urllib.parse.quote(n) # 将数据编码
pc = "province=" + p + "&city=" + c + "¬e=" + n
res = urllib.request.urlopen(url, data=pc.encode()) # 其中data表单提交的为二进制数据
data = res.read()
html = data.decode()