import mechanize,cookielib
br=mechanize.Browser()
cookie_jar=cookielib.CookieJar()
br.set_cookiejar(cookie_jar)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
br.set_handle_referer(True)
br.set_handle_robots(False)
br.open("http://facebook.com/login.php")
br.select_form(nr=0)
br.form['email']=raw_input("Email please: ")
br.form['pass']=raw_input("Password please: ")
br.submit()
if "Logout" in br.response().read():
print "Successfuly Logged in...May the Spam Process Begin ;) "
else:
print "Something is wrong with logging in.Sorry :( "
link_to_spam=raw_input("Enter the messages link for the one you want to spam\n\
Example: https://www.facebook.com/messages/someone: ")
br.open(link_to_spam)
for f in br.forms():
print f
所以这段代码没有在facebook中显示消息形式。并且不对代码的目的发表评论。我只是为了好玩而编码,除了接受我的朋友之外不会使用它但即便如此,我也不会使用它。 有没有人知道它为什么没有显示?
答案 0 :(得分:7)
我不确定他们是否使用表单来处理邮件,这可能是javascript。无论哪种方式,这都可以通过Selenium完成。
首先,安装Selenium:https://pypi.python.org/pypi/selenium
然后从此处下载Chrome驱动程序:https://code.google.com/p/chromedriver/downloads/list
将二进制文件放在与您正在编写的python脚本相同的文件夹中。 (或者将其添加到路径或其他内容,更多信息请点击此处:https://code.google.com/p/selenium/wiki/ChromeDriver)
之后,以下代码应该有效:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
email = raw_input("Email: ")
password = raw_input("Password: ")
person =raw_input("Enter the messages link for the one you want to spam\n\
Example: https://www.facebook.com/messages/someone: ")
driver.get("http://www.facebook.com")
elem = driver.find_element_by_id("email")
elem.send_keys(email)
elem = driver.find_element_by_id("pass")
elem.send_keys(password)
elem.send_keys(Keys.RETURN)
driver.get("https://facebook.com/messages/"+person)
elem = driver.find_element_by_css_selector("div textarea.uiTextareaNoResize")
elem.send_keys("python test")
elem.send_keys(Keys.RETURN)
它实际上会在新窗口中打开chrome并在浏览器中输入文本。
答案 1 :(得分:0)
几乎所有事情都有效但不是:
elem = driver.find_element_by_css_selector("div textarea.uiTextareaNoResize")
elem.send_keys("python test")
elem.send_keys(Keys.RETURN)
应该有一些其他代码而不是:
elem = driver.find_element_by_css_selector("div textarea.uiTextareaNoResize")