Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to send a message from google form to a python

import urllib.request
from bs4 import BeautifulSoup
import requests, warnings
def get_questions(in_url):
    res = urllib.request.urlopen(in_url)
    soup = BeautifulSoup(res.read(), 'html.parser')
    get_names = lambda f: [v for k,v in f.attrs.items() if 'label' in k]
    get_name = lambda f: get_names(f)[0] if len(get_names(f))>0 else 'unknown'
    all_questions = soup.form.findChildren(attrs={'name': lambda x: x and x.startswith('entry.')})
    return {get_name(q): q['name'] for q in all_questions}
def submit_response(form_url, cur_questions, verbose=False, **answers):
    submit_url = form_url.replace('/viewform', '/formResponse')
    form_data = {'draftResponse':[],
                'pageHistory':0}
    for v in cur_questions.values():
        form_data[v] = ''
    for k, v in answers.items():
        if k in cur_questions:
            form_data[cur_questions[k]] = v
        else:
            warnings.warn('Unknown Question: {}'.format(k), RuntimeWarning)
    if verbose:
        print(form_data)
    user_agent = {'Referer':form_url,
                  'User-Agent': "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36"}
    return requests.post(submit_url, data=form_data, headers=user_agent)
Comment

how to send a message from google form to a python

import urllib
import urllib2

user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'
header={'User-Agent' : user_agent}
url = "http://....Your google form"
# values from your form. You will need to include any hidden variables if you want to..
values= {
'entry.asdfsdfsdasd': 'asdfasdfsd',
'draftResponse':'[,,"-asdfasdasdf"]',
'pageHistory':'0',
'fbzx':'-asdfasdfsd'
}
data = urllib.urlencode(values)
urllib2.Request(url, data, header)
Comment

PREVIOUS NEXT
Code Example
Python :: prime number program in python 
Python :: pandas query like 
Python :: random variables python 
Python :: write specific columns to csv pandas 
Python :: filter an importrange 
Python :: most frequent element in a list 
Python :: python check is admin 
Python :: python requests set header cookie 
Python :: how to get the amount of nan values in a data fram 
Python :: python transfer file 
Python :: random element python 
Python :: django run queryset in terminal 
Python :: leaky relu keras 
Python :: update python in cmd 
Python :: python list minus list 
Python :: discord.py owner only commands 
Python :: calcolatrice 
Python :: discord.py commands.group 
Python :: python get time difference in milliseconds 
Python :: english to japanese 
Python :: flask hello world 
Python :: combine 2 dataframes based on equal values in columns 
Python :: python discord input 
Python :: cross validation python 
Python :: NameError: name ‘pd’ is not defined 
Python :: pd max rows set option 
Python :: read tsv file column 
Python :: read data from yaml file in python 
Python :: vscode not recognizing python import 
Python :: python draw polygon 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =