Python post request for comment website

Ramazan

Regular Member
Joined
Aug 19, 2018
Messages
433
Reaction score
308
Trying to auto post this website but something wrong I can get response 200 but comment is not going..
Python:
import requests

headers = {
    'authority': 'lucian.uchicago.edu',
    'method': 'POST',
    'path': '/blogs/atomicage/wp-comments-post.php' ,
    'scheme': 'https',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'tr-TR, trq = 0.9, en-USq = 0.8, enq = 0.7',
    'cache-control': 'max-age = 0',
    'content-type': 'application/x-www-form-urlencoded',
    'origin': 'https://lucian.uchicago.edu',
    'referer': 'https://lucian.uchicago.edu/blogs/atomicage/2017/05/29/us-nuclear-disaster-could-be-worse-than-fukushima-experts-warn-via-news-wire/comment-page-57/',
    'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"',
    'sec-ch-ua-mobile': '?0',
    'sec-fetch-dest': 'document',
    'sec-fetch-mode': 'navigate',
    'sec-fetch-site': 'same-origin',
    'sec-fetch-user': '?1',
    'upgrade-insecure-requests': '1',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36'                                                               
}

PARAMS = {
    'c89d734f3a': 'Contentdemo',
    'author': 'authorthing',
    'email': '[email protected]',
    'url': 'demo.com',
    'submit': 'Post comment'
}

response = requests.post(
    'https://lucian.uchicago.edu/blogs/atomicage/2017/05/29/us-nuclear-disaster-could-be-worse-than-fukushima-experts-warn-via-news-wire/comment-page-57/', headers=headers, params=PARAMS)
print(response)
 
The params argument appends your data on the posting URL as query strings. I would try using the data argument instead of params.

Python:
response = requests.post(
    'https://lucian.uchicago.edu/blogs/atomicage/2017/05/29/us-nuclear-disaster-could-be-worse-than-fukushima-experts-warn-via-news-wire/comment-page-57/', headers=headers, data=PARAMS)

https://docs.python-requests.org/en/master/user/quickstart/#more-complicated-post-requests
Thanks for your answer. I talked with someone for this they said you should make this with selenium because when I have more than 100 bots and if site change post things I will lose too much time. Butt selenium is real solution for this bot project.
 
Puppeteer is another automation tool you can look into but, if you already have somebody helping you and they know selenium then I would stick to that.
 
What is that
Code:
'c89d734f3a': 'Contentdemo',
thing?

It could be a csrf token generated on each page view. If it does not match, posting wouldn't work anyway.
 
Puppeteer is another automation tool you can look into but, if you already have somebody helping you and they know selenium then I would stick to that.
Actually i know selenium enough. Thats why tried to learn faster and different thing POST. But in this project selenium is better imo. Do u think for those automation js or python better for scaling?
 
Trying to auto post this website but something wrong I can get response 200 but comment is not going..
Python:
import requests

headers = {
    'authority': 'lucian.uchicago.edu',
    'method': 'POST',
    'path': '/blogs/atomicage/wp-comments-post.php' ,
    'scheme': 'https',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'tr-TR, trq = 0.9, en-USq = 0.8, enq = 0.7',
    'cache-control': 'max-age = 0',
    'content-type': 'application/x-www-form-urlencoded',
    'origin': 'https://lucian.uchicago.edu',
    'referer': 'https://lucian.uchicago.edu/blogs/atomicage/2017/05/29/us-nuclear-disaster-could-be-worse-than-fukushima-experts-warn-via-news-wire/comment-page-57/',
    'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"',
    'sec-ch-ua-mobile': '?0',
    'sec-fetch-dest': 'document',
    'sec-fetch-mode': 'navigate',
    'sec-fetch-site': 'same-origin',
    'sec-fetch-user': '?1',
    'upgrade-insecure-requests': '1',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36'                                                              
}

PARAMS = {
    'c89d734f3a': 'Contentdemo',
    'author': 'authorthing',
    'email': '[email protected]',
    'url': 'demo.com',
    'submit': 'Post comment'
}

response = requests.post(
    'https://lucian.uchicago.edu/blogs/atomicage/2017/05/29/us-nuclear-disaster-could-be-worse-than-fukushima-experts-warn-via-news-wire/comment-page-57/', headers=headers, params=PARAMS)
print(response)
Try mechanize, MechanicalSoup or RoboBrowser module to submit the form. The proccess will be lighter than Selenium and your code smaller and simplier than that one above.
 
Try mechanize, MechanicalSoup or RoboBrowser module to submit the form. The proccess will be lighter than Selenium and your code smaller and simplier than that one above.
Actually that code is more faster than those things... Idk I will check those mechsoup and robo things thanks
 
Trying to auto post this website but something wrong I can get response 200 but comment is not going..
Python:
import requests

headers = {
    'authority': 'lucian.uchicago.edu',
    'method': 'POST',
    'path': '/blogs/atomicage/wp-comments-post.php' ,
    'scheme': 'https',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'tr-TR, trq = 0.9, en-USq = 0.8, enq = 0.7',
    'cache-control': 'max-age = 0',
    'content-type': 'application/x-www-form-urlencoded',
    'origin': 'https://lucian.uchicago.edu',
    'referer': 'https://lucian.uchicago.edu/blogs/atomicage/2017/05/29/us-nuclear-disaster-could-be-worse-than-fukushima-experts-warn-via-news-wire/comment-page-57/',
    'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"',
    'sec-ch-ua-mobile': '?0',
    'sec-fetch-dest': 'document',
    'sec-fetch-mode': 'navigate',
    'sec-fetch-site': 'same-origin',
    'sec-fetch-user': '?1',
    'upgrade-insecure-requests': '1',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36'                                                             
}

PARAMS = {
    'c89d734f3a': 'Contentdemo',
    'author': 'authorthing',
    'email': '[email protected]',
    'url': 'demo.com',
    'submit': 'Post comment'
}

response = requests.post(
    'https://lucian.uchicago.edu/blogs/atomicage/2017/05/29/us-nuclear-disaster-could-be-worse-than-fukushima-experts-warn-via-news-wire/comment-page-57/', headers=headers, params=PARAMS)
print(response)
I gave a quick look, you are posting to the wrong URL
You must post to:
https://lucian.uchicago.edu/blogs/atomicage/wp-comments-post.php
There are also some hidden fields on the form that you must pass on the data. You can extract these by targetting the inputs with the name comment_post_ID and comment_parent from the original blog page (https://lucian.uchicago.edu/blogs/a...se-than-fukushima-experts-warn-via-news-wire/)

"https://lucian.uchicago.edu/blogs/a...a-experts-warn-via-news-wire/comment-page-57/" (the page you are trying to post to) is the page you get redirected to, after you successfully make the post under the 1st URL.


Also for people that are saying to use selenium, that's totally an overkill here.
 
I gave a quick look, you are posting to the wrong URL
You must post to:
https://lucian.uchicago.edu/blogs/atomicage/wp-comments-post.php
There are also some hidden fields on the form that you must pass on the data. You can extract these by targetting the inputs with the name comment_post_ID and comment_parent from the original blog page (https://lucian.uchicago.edu/blogs/a...se-than-fukushima-experts-warn-via-news-wire/)

"https://lucian.uchicago.edu/blogs/a...a-experts-warn-via-news-wire/comment-page-57/" (the page you are trying to post to) is the page you get redirected to, after you successfully make the post under the 1st URL.


Also for people that are saying to use selenium, that's totally an overkill here.
Python:
data = {
  'c89d734f3a': 'Demo content lol',
  'comment': '',
  'author': 'eauthor',
  'email': '[email protected]',
  'url': 'asdasd.com',
  'submit': 'Post comment',
  'comment_post_ID': '42287',
  'comment_parent': '0'
}

response = requests.post('https://lucian.uchicago.edu/blogs/atomicage/wp-comments-post.php', headers=headers, data=data)
print(response.content)
This code working thanks for helping
 
Could requests also be used to send forums posts? As i would like to send updates / replys to my own posts

Edit: happened to find that i would need to manage login sessions also and after staying logged in i could send it
 
Last edited:
Back
Top