Last active
August 29, 2015 13:55
-
-
Save Rembane/8730222 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment