Seite 1 von 1

Create New Comment In Xenforo

Verfasst: Freitag 19. Dezember 2014, 14:32
von wichit12
Hi,

https://xenforo.com/community/threads/n ... nbsp.3864/

i want to add new comment "thanks" to above topic
It can login but can not reply topic.
Here my code, please help me fix. Thanks a lot

Code: Alles auswählen

import requests 
with requests.session() as c: 
    url='https://xenforo.com/community/login/login' 
    USERNAME='minneconsin@gmail.com' 
    PASSWORD='Demo12345' 
    c.get(url) 
    session=requests.session() 
    login_data=dict(login=USERNAME,password=PASSWORD,next="/") 
    c.post(url,data=login_data,headers={"Referer":"https://xenforo.com/community/"}) 

    thisvalues='Thanks' 
    thisurl='https://xenforo.com/community/threads/nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp.3864/' 

    r=requests.post(thisurl,data=thisvalues) 
    session.close() 
    session.__exit__() 

Re: Create New Comment In Xenforo

Verfasst: Freitag 19. Dezember 2014, 14:38
von Sirius3
@wichit12: do you get some error message?

Why do you introduce the variable session? It's never used. And you should not call __exit__ directly, that's only used by the with-statement. Your second post request is not done in the same session as the login request. You probably ment `r=c.post(thisurl, data=thisvalues)`. Btw. `c` is no good name for a variable, because the name should mean something, the same with `thisvalues` and `thisurl`; the `this` doesn't add any information to the name.

Re: Create New Comment In Xenforo

Verfasst: Freitag 19. Dezember 2014, 14:59
von wichit12
@sirius3

Thanks for your advices. How to fix my code? help me pls

Re: Create New Comment In Xenforo

Verfasst: Freitag 19. Dezember 2014, 15:05
von Sirius3
@wichit12: read my answer.

Re: Create New Comment In Xenforo

Verfasst: Samstag 20. Dezember 2014, 02:35
von wichit12
@sirius3

Code: Alles auswählen

import requests
with requests.session() as c:
    url='https://xenforo.com/community/login/login'
    USERNAME='minneconsin@gmail.com'
    PASSWORD='Demo12345'
    c.get(url)
    login_data=dict(login=USERNAME,password=PASSWORD,next="/")
    c.post(url,data=login_data,headers={"Referer":"https://xenforo.com/community/"})

    values='This is auto reply'
    url2='https://xenforo.com/community/threads/nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp.3864/'
    r=c.post(url2,data=values)
    page=c.get('https://xenforo.com/community/threads/nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp.3864/page-2')
    print(page.content)
No error but can't add comment "this is auto test" to that topic. Please help me fix it.

Re: Create New Comment In Xenforo

Verfasst: Sonntag 21. Dezember 2014, 00:19
von BlackJack
@wichit12: You'll have to do what a browser would do to add a reply. The Firebug addon for Firefox can be useful to analyse the communication between the browser and the server while adding a post manually.

Re: Create New Comment In Xenforo

Verfasst: Sonntag 21. Dezember 2014, 04:50
von wichit12
@BlackJack

Can you help me fix my code?. Tks a lot