Hi guys i would like to give me some hints about how to click a javascript button using Python.

My goal is to make a script that can login at my Facebook page and then post a Message at my Wall.

The first part i have already done it, it logs in successfully into my Profile page. But then, in order to Write something into the field and submit it requires some Javascript.

Here it is my code so far [ i have change my gredentials like user, pass, composer's_id..] Also you have to make a file logs.txt. There the code of the Profile Source Code will be print out so you can test and search if you did it

#coding=utf-8
import urllib, urllib2, cookielib

user = 'YOUR_USERNAME'
passwd = 'YOUR_PASSWORD'

file = './logs.txt'

url_login = "https://login.facebook.com/login.php?"
url_action = "https://login.facebook.com/login.php?login_attempt=1"
url_topic = "http://www.facebook.com/home.php?#!/profile.php?id=YOUR_ID_NUMBER_FOUND_FROM_SOURCE_CODE_OF_PAGE"
url_index = "https://login.facebook.com/login.php?"


def login(user, password, url_action):
    cj = cookielib.LWPCookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
    urllib2.install_opener(opener)
    opener.addheaders=[('Content-Type','application/x-www-form-urlencoded'),('Connection','keep-alive'),('User-Agent','Mozilla/5.0')]
    params = urllib.urlencode({'action':url_action , 'referer':url_index, 'email':user, 'pass':passwd, 
                                  'loginTrue':"login"})

    f = opener.open(url_action, params)
    f.close()
    f = opener.open(url_action, params)
    f.close()
    return opener


def make_post(opener, url_topic, post):
    url_index = "http://www.facebook.com/?ref=home#!/home.php/ajax/updatestatus.php"  
    params = urllib.urlencode(dict(action= url_index, enctype="multipart/form-data", status = 'Τι σκέφτεστε;',
                                    charset_test='€,´,€,´,水,Д,Є', fb_dtsg='xq13S',
                                    composer_id='xxxxxxxxxxxxxxxx', profile_id='xxxxxxxxxxx',
                                    target_id='0', display_context='home'))
    f = opener.open(url_topic, params)
    f.close()


def get_source_code( opener, url_x ):
    f = opener.open(url_x)
    data = f.read()
    print type(data)
    f.close()
    return data


def keep_log( data, file ):
    f = open(file, 'w')
    f.write(data)
    f.close()


opener = login(user, passwd, url_action)
src_code = get_source_code(opener, url_topic)
keep_log(src_code, file)
print src_code
make_post(opener, url_topic, "test")

I am Greek so some part should be filled in the appropriate language if you want to try it.

link|flag
6  
Try stackoverflow.com – Jeff O Dec 8 at 18:17

closed as off topic by Josh K, Adam Crossland, Inaimathi, Michael, John Straka Dec 8 at 18:42

Questions on Programmers are expected to be about subjective issues in software development, within the scope defined in the faq.