Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

fill out a webform that uses javascript with python

i am trying to fill out a webform using a python program by submitting specific values. the problem is it uses javascript. i will post an example of the value i want to fill.

fo.addVariable("email","[email protected]")
fo.addVariable("age","19")
fo.addVariable("gender","M")
fo.addVariable("line","hello")

that is an example of the value on the page. what i want to do is submit a value to that and change it. what i am currently attempting is this:

data = urllib.parse.urlencode({"line": "hello", "age": "50", "email":  "[email protected]", "gender": "M"}).encode()
resp = urlreq.urlopen("http://url.com/update", data) 

this usually works for most webforms. but for this one it will not.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In python 2.7, urllib has no attribute urllib.parse and a .encode() function at the end is unnecessary.

I think what you should be writing is

data = urllib.urlencode({"line": "hello", "age": "50", "email":  "[email protected]", "gender": "M"})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...