0

Long story short I need to post automated comments to my WordPress blog. I find mechanize for Python (hurray! no need to muck around in PHP!) but I can't post comments with it. According to the debug info I logged in successfully and returned to the comment page, but comments don't show. What's weirder is that when I try posting the same thing twice, I get the feedback "duplicate comment detected" as if it had already been posted... WTF? Revelant bits of my code:

br = mechanize.Browser()

cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)

br.set_debug_redirects(True)
br.set_debug_responses(True)
br.set_debug_http(True)

logger = logging.getLogger('mechanize')
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.INFO)

br.open('some wordpress comment page')

response = br.follow_link(url_regex=r'wp-login')

br.select_form(nr=0)
br['log'] = username
br['pwd'] = passwd
br.submit()

# the above logs me in successfully

br.select_form(nr=1)
br['comment'] = comment

response = br.submit()

...doesn't work. Any ideas?

Kristoff vdH
  • 224
  • 2
  • 4

1 Answers1

0

it's possible that code built into the blog is detecting the user agent string and refusing to show the comments, but I have little experience with either Wordpress code or this python module.

mechanize looks like a spammer's best friend otherwise. Oh of course there are thousands of legitimate uses (and I'm not accusing you of course).

Could you look into the logs of your blog (access_log if you are using Apache) and see what your script is hitting your blog with?

Christian Specht
  • 35,843
  • 15
  • 128
  • 182