Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created February 16, 2011 07:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marshluca/828999 to your computer and use it in GitHub Desktop.
Save marshluca/828999 to your computer and use it in GitHub Desktop.
豆瓣自动顶贴
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)
@junfan
Copy link

junfan commented Jul 11, 2013

这个有用么..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment