Created
April 29, 2014 17:21
-
-
Save nemumu/11406662 to your computer and use it in GitHub Desktop.
Twitterアカウントを作成するサンプルプログラム
This file contains 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
# 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