Created
February 16, 2011 07:35
-
-
Save marshluca/828999 to your computer and use it in GitHub Desktop.
豆瓣自动顶贴
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'mechanize' | |
def comment_douban_topic(url,text) | |
login_url = "http://www.douban.com/login" | |
agent = Mechanize.new | |
# agent.set_proxy("218.201.21.176","80") | |
agent.user_agent_alias = "Googlebot" | |
page = agent.get(login_url) | |
form = page.forms.last | |
form.form_email = "your email" | |
form.form_password = "your password" | |
page = agent.submit(form) | |
# puts agent.cookie_jar.inspect | |
page = agent.get(url) | |
comment_form = page.forms.last | |
comment_form.rv_comment = text | |
page = agent.submit(comment_form) | |
puts page.body | |
end | |
# 这里必须是该topic的最后一页,也就是评论框出现的页面 | |
topic_url = "http://www.douban.com/group/topic/1105027/?start=200" | |
comment_content = "大江东去,浪淘尽,千古风流人物。故垒西边,人道是,三国周郎赤壁。乱石穿空,惊涛拍岸,卷起千堆雪。" | |
comment_douban_topic(topic_url,comment_content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这个有用么..