Skip to content

Instantly share code, notes, and snippets.

@nemumu
Created April 29, 2014 17:21
Show Gist options
  • Save nemumu/11406662 to your computer and use it in GitHub Desktop.
Save nemumu/11406662 to your computer and use it in GitHub Desktop.
Twitterアカウントを作成するサンプルプログラム
# coding:utf-8
import requests
import re
user_name = "UserName" # ユーザー名
screen_name = "Screen_name" # screen_name・ユーザーID
password = "Password" # パスワード
mailAddress = "mail@example.com" # メールアドレス
url = 'https://twitter.com/signup'
sess = requests.session()
r = sess.get(url)
cookie_Session = r.cookies["_twitter_sess"]
cookie_GuestID = r.cookies["guest_id"]
html = r.text
r = re.compile('<input type="hidden" value=".{40}" name="authenticity_token"/>')
match = r.search(html)
authKey = ""
if match:
authKey = match.group().strip('<input type="hidden" value="')
authKey = authKey.strip('" name="authenticity_token"/>')
else:
print "NotFound Authenticity_Token"
url = 'https://twitter.com/account/create'
params = {}
params['authenticity_token'] = authKey
params['user[name]'] = user_name
params['user[email]'] = mailAddress
params['user[user_password]'] = password
params['user[screen_name]'] = screen_name
params['user[remember_me_on_signup]'] = '1'
params['user[use_cookie_personalization]'] = '1'
params['asked_cookie_personalization_setting'] = '1'
params['context'] = ''
params['ad_id'] = ''
params['ad_ref'] = ''
params['user[discoverable_by_email]'] = '1'
params['user[send_email_newsletter]'] = '1'
cookie = {'_twitter_sess' : cookie_Session, 'guest_id' : cookie_GuestID}
r = sess.post(url,cookies=cookie, params=params)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment