Skip to content

Instantly share code, notes, and snippets.

@ctosib
Created December 27, 2016 16:43
Show Gist options
  • Save ctosib/c7f79eb279954af8d75013325cd3eb67 to your computer and use it in GitHub Desktop.
Save ctosib/c7f79eb279954af8d75013325cd3eb67 to your computer and use it in GitHub Desktop.
利用requests和beautifulsoup成功填寫google表單
import requests
from bs4 import BeautifulSoup as bs
#form的action網址
url = 'https://docs.google.com/forms/d/e/1FAIpQLSfG0Jrb1XB0_6bnStQqI3LTh1vJxzNf92X38O9n9gINR3pERQ/formResponse'
r = requests.Session()
res = r.get('https://docs.google.com/forms/d/e/1FAIpQLSfG0Jrb1XB0_6bnStQqI3LTh1vJxzNf92X38O9n9gINR3pERQ/viewform')
soup = bs(res.content,'html.parser')
inputlist = soup.find_all('input')
textarealist = soup.find_all('textarea')
test={}
count = raw_input("input total:")
kind = raw_input("input kind:")
for i in inputlist:
print i['name']+':'+i['value']
#輸入金額的欄位name
if i['name']=='entry.1345339955':
test.update({i['name']:count})
else:
test.update({i['name']:i['value']})
for j in textarealist:
#print j['name']+':'+j['value']
test.update({j['name']:kind.decode('utf-8')})
res = r.post(url,data=test)
print res.status_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment