Skip to content

updated README.md, Fixed & Optimized fb.py #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ENV
ghostdriver.log
phantomjs.exe
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
# FbPostUsingPython
>It is a small script to post status on your FB wall using python..!
>It is a small script to post status on your FB wall using python

#Installation
1- Install python 3.5 from [Python.org](https://www.python.org)
# Installation
* Install python 3 from [Python.org](https://www.python.org)

2- `sudo apt-get install python3-pip` (For Ubuntu Users)
* Install pip `$ sudo apt-get install python3-pip` (For Ubuntu Users)

3- `python setup.py` or `python3 setup.py`
* `$ python setup.py` or `$ python3 setup.py`

This will install all these packages
* Download [PhantomJS](http://phantomjs.org/download.html) and copy the exe file into the same folder as your repository

* `pip install bs4`

* `pip install selenium`

After the installation, open terminal at the root folder--
After the installation, open terminal at the root folder

Run `python fb.py` or `python3 fb.py` to post status from terminal or cmd.

Note:- Use Mozilla Firefox V40.0 to make this script work for you.

##Some Useful Installation Tips ( Ubuntu )

If you have already installed python 2.7 install python 3 as well but it may be the problem that the packages installed with respect to python 2.7 and shows error for the python 3 packages,
## Some Useful Installation Tips ( Ubuntu )

If you have already installed python 2.7 install python3 as well but it may be the problem that the packages are installed with respect to python 2.7 and shows error for the python 3 packages,

So you need to install virtual Environment for the python 3 to install python3 packages.
So, you need to install a Virtual Environment for the python3 to install python3 packages.

```
virtualenv -p /usr/bin/python3 py3env
Expand All @@ -34,7 +30,7 @@ So you need to install virtual Environment for the python 3 to install python3 p

After setting virtual environment install packages listed above and Enjoy.

#License
# License

Copyright (c) 2016 Ankit Jain - Released under the Apache License

Expand Down
32 changes: 19 additions & 13 deletions fb.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import time
import os
import getpass
import selenium
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.phantomjs.webdriver import WebDriver


def get_title(driver):
html_page = driver.page_source
soup = BeautifulSoup(html_page,'html.parser')
print(soup.title.string+"\n")
# print(soup.title.string+"\n")
return soup.title.string

binary = FirefoxBinary('C:\Program Files (x86)\Mozilla Firefox\Firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)
url = "https://facebook.com"
if os.name == 'nt':
pathr = 'phantomjs.exe'
else:
pathr = './phantomjs'
driver = webdriver.PhantomJS(pathr, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
url = "https://mbasic.facebook.com/"

while True:
driver.get(url)
time.sleep(2)
# time.sleep(2)
get_title(driver)

eMail = input("Enter your Email Id or Mobile No. to Login\n")
Expand All @@ -30,24 +34,26 @@ def get_title(driver):
password = driver.find_element_by_name("pass")
password.send_keys(pAss)

login = driver.find_element_by_css_selector("#u_0_l")
login = driver.find_element_by_name("login")
login.click()
time.sleep(5)
# time.sleep(5)


if get_title(driver) != "Log in to Facebook | Facebook":
print("You are logged in now\n")
#afterlogin the url changes so we need to set the url again
driver.get(url)

pp = input("Enter your Status\n")
# status = driver.find_element_by_xpath('//textarea[@class="uiTextareaAutogrow _3en1" or @class="uiTextareaAutogrow _3en1 _480e"]')
status = driver.find_element_by_xpath('//textarea[contains(@class, "uiTextareaAutogrow")]')
status = driver.find_element_by_name("xc_message")

status.send_keys(pp)
button = driver.find_element_by_xpath('//div[@class="clearfix"]/div[contains(@class, "rfloat")]/div/button[@type="submit" and @value="1"]')
button = driver.find_element_by_name("view_post")
button.click()
time.sleep(5)
# time.sleep(5)
print("Your Status : '"+pp+"' has been uploaded!\n")
driver.quit()
break

else:
print("Invalid Email Id or Password, Try Login Again\nCtrl+C to exit the script\n")
print("Invalid Email Id or Password, Try Login Again\nCtrl+C to exit the script\n")