Python Mechanize log into Facebook cookie error

前端 未结 2 1385
小蘑菇
小蘑菇 2020-12-15 12:10

Since a few days I cannot log into facebook anymore with my script. The Facebook login page gives the error:

Cookies required, cookies are not enabled on your brow

相关标签:
2条回答
  • 2020-12-15 12:48

    Assuming that how do you log in is not important (as you were prepared to use your Mozilla cookies to do so), you can use the mobile website to accomplish it.

    First, you log in to Facebook using its mobile version (which will not require cookies), then redirect your browser to the page you wanted to save.

    Minor changes to your code:

    user = "EMAIL"
    passwd = "PASSWORD"
    url = "https://m.facebook.com/login.php"
    
    #Open URL and submit
    br.open(url)
    br.select_form(nr=0)
    br.form['email'] = user
    br.form['pass'] = passwd
    br.submit()
    
    response = br.open("https://www.facebook.com/")
    
    #Opens website and write source to html-output.txt
    fileobj = open("HTML-OUTPUT.txt","wb")
    fileobj.write(response.read())
    fileobj.close()
    
    0 讨论(0)
  • 2020-12-15 12:50

    I would recommend you to use this reusable application made for this purpose:

    $ pip install django-oauth-tokens
    

    And after in terminal

    >>> from oauth_tokens.providers.facebook import FacebookAuthRequest
    >>> req = FacebookAuthRequest(username='...', password='...')
    >>> response = req.authorized_request(url='https://facebook.com')
    >>> response.content.count(USER_FULL_NAME)
    >>> fileobj = open("HTML-OUTPUT.txt","wb")
    >>> fileobj.write(response.content)
    >>> fileobj.close()
    4
    
    0 讨论(0)
提交回复
热议问题