首页 新闻 会员 周边 捐助

如何对一个动态网页传递参数

0
悬赏园豆:30 [已解决问题] 解决于 2018-02-21 12:35
编写脚本抓取网页信息,获得最终的答案这一步我已经弄完了,但是在如何提交的问题上不知道如何下手。
抓取的包如下
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}
 
 
 
 
 
 
绝地绅士的主页 绝地绅士 | 初学一级 | 园豆:163
提问于:2018-02-17 21:02
< >
分享
最佳答案
0

 这是一个get请求提交就行了,

requests.get('http://121.42.176.204:23331/calculator/?answer=1212') 

r = requests.get(‘http://121.42.176.204:23331/calculator/, params={”answer“:1212')}) 也行

收获园豆:30
罗梁 | 菜鸟二级 |园豆:232 | 2018-02-20 17:33

这个网站的话,可能还需要保持会话才行的。

s = requests.Session()

然后用s去请求

s.get()

罗梁 | 园豆:232 (菜鸟二级) | 2018-02-20 17:35

@罗梁: 谢谢,虽然我已经解决了,就是用的这个方法

绝地绅士 | 园豆:163 (初学一级) | 2018-02-21 12:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册