编写脚本抓取网页信息,获得最终的答案这一步我已经弄完了,但是在如何提交的问题上不知道如何下手。
抓取的包如下
GET /calculator/ HTTP/1.1
Host: 121.42.176.204:23331
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:58.0) Gecko/20100101 Firefox/58.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Cookie: userhash=758e73be2b014b24fc1a596f6a5bc7e3b84c3645; PHPSESSID=5ced3a0a93872e17d41ed521dafd0eac
Connection: close
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0
----------------------------------------------------
GET /calculator/?answer=888 HTTP/1.1
Host: 121.42.176.204:23331
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:58.0) Gecko/20100101 Firefox/58.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Referer: http://121.42.176.204:23331/calculator/
Cookie: userhash=758e73be2b014b24fc1a596f6a5bc7e3b84c3645; PHPSESSID=5ced3a0a93872e17d41ed521dafd0eac
Connection: close
Upgrade-Insecure-Requests: 1
我下一步该怎么弄啊:
写的脚本在这:
import requests
import request
def NUM(s,oth=''):
s2 = s.lower();
fomart = 'abcdefghijklmnopqrstuvwxyz0123456789'
for c in s2:
if not c in fomart:
s = s.replace(c,'');
return s;
r = requests.get('http://121.42.176.204:23331/calculator/')
m = r.text
m1=m[515:523]
m2=m[524:532]
m3=m[533:540]
m4=m[541:549]
n1=NUM(m1)
n2=NUM(m2)
n3=NUM(m3)
n4=NUM(m4)
num1=int(n1)
num2=int(n2)
num3=int(n3)
num4=int(n4)
number = num1+num2*num3-num4
print(number)#number就是结果
content = {'answer':number}