python构造POST

import urllib.parse
import urllib.request
import http.cookiejar
import bs4

cookie_filename = 'cookie.txt'
cookie = http.cookiejar.LWPCookieJar(cookie_filename)
handler = urllib.request.HTTPCookieProcessor(cookie)
opener = urllib.request.build_opener(handler)

data2 = bytes(urllib.parse.urlencode({'word':'input'}),encoding='utf8')
request2 = urllib.request.Request('http://10.10.10.1:80/index.html',data=data2,method='POST')
response4=opener.open(request2)
html=response4.read().decode('gbk')
print(html)

  

posted @ 2020-08-29 12:10  liyilong  阅读(266)  评论(0)    收藏  举报