academica academica - 11 months ago 81
Python Question

login to facebook using the python package

The task is login on facebook page using a webengine. I have choosen for this. Installed pySide, Flask and paste modules and got with command 'pip install' eventually.
My login script is simple:

from ghost import Ghost
ghost = Ghost()
session = ghost.start()
page, resources ='')

result, resources = session.set_field_value("input[id=email]", 'email')
result, resources = session.set_field_value("input[id=pass]", 'passssss')

page, resources ="form", "submit", expect_loading=True)

But when I'm using my windows PC I see "enable cookie in your browser" message on facebook page. When I use my laptop with fedora installed I logins successfully.
What is the difference and how to beat this issue?
I guess it is old webkit version on my windows PC.

Answer Source

As at this time, I am able to log into Facebook on my Windows PC with the code below. Any time it changes as a result of upgrade from their end, then alter the affected part. Cheers.

from ghost import Ghost, Session

ghost = Ghost()
USERAGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"

with ghost.start():
    session = Session(ghost, download_images=False, display=True, user_agent=USERAGENT)
    page, rs ="", timeout=120)
    assert page.http_status == 200

    document.querySelector('input[name="email"]').value = '';
    document.querySelector('input[name="pass"]').value = 'email-password';


    import codecs

    with'fb.html', encoding='utf-8', mode='w') as f:

    # session.save_cookies('fbookie')

    # gracefully clean off to avoid errors