Skip to content

Instantly share code, notes, and snippets.

@Rembane
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rembane/8730222 to your computer and use it in GitHub Desktop.
Save Rembane/8730222 to your computer and use it in GitHub Desktop.
# encoding: utf-8
from bs4 import BeautifulSoup
from Cookie import SimpleCookie
import requests
url_template = u'http://wiki.sverok.se/w/index.php?title={}&action=edit'
with open('cookie.txt') as fh:
cookies = {k : v.value for k,v in SimpleCookie(fh.read()).items()}
s = requests.Session()
r = s.get(url_template.format(u'Andreas_lekplats'), cookies=cookies)
soup = BeautifulSoup(r.text)
data = {}
ignore = {'wpWatchthis', 'wpPreview', 'wpDiff', 'wpTextbox1', 'wpMinoredit'}
for e in soup.find(id='editform').find_all(['input', 'textarea']):
if e['name'] in ignore:
continue
elif e.name == 'input':
data[e['name']] = e.get('value', '')
elif e.name == 'textarea':
data[e['name']] = e.string
data['wpTextbox1'] = u'Andreas testar!'
data['wpSummary'] = u'Sidan skapad av Hej Kommunen-projektet.'
r2 = s.post(url_template.format(u'Andreas_lekplats'), cookies=cookies, data=data)
print r2.text.encode('utf-8')
#for e in soup.find(id='editform').find_all(['input', 'textarea']):
# print e.name.encode('utf-8')
# for k,v in sorted(e.attrs.items()):
# print u'\t{}\t{}'.format(k,v).encode('utf-8')
# print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment