在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python/ 如何用python模擬豆瓣發(fā)帖?

如何用python模擬豆瓣發(fā)帖?

是這樣的,我在網(wǎng)上也看了一些代碼,在github也有,但是有一點(diǎn)我不太懂,我已經(jīng)成功模擬豆瓣登陸(python 3.5),但在發(fā)帖時(shí)出了點(diǎn)問題

代碼如下

addtopicurl = "http://www.douban.com/group/PythonCore/new_topic"
res=opener.open(addtopicurl)
html=res.read()
html =html.decode('utf-8')
m= re.search('<input type="hidden" name="topic_id" value="(.+?)">', html)
p["topic_id"] = m.group(1)
m= re.search('<input type="hidden" name="topic_id_sig" value="(.+?)">', html)
p["topic_id_sig"] = m.group(1)
p["rev_title"] = 'hello,world'
p["rev_text"] = 'Hello.it's a test message using python'
p["rev_submit"] = '好了,發(fā)言'

結(jié)果會(huì)返回
AttributeError: 'NoneType' object has no attribute 'group'

Traceback (most recent call last):
File "C:UsersAdministratorDesktop001copy.py", line 70, in <module>

p["topic_id"] = m.group(1)

我研究了半天沒搞明白,python菜鳥,請(qǐng)大家指教
我看到也有這樣寫的
data = {

                    "ck": "NBJ2",
                    "comment": "模擬登錄"
                }
                session=requests.session()
                r = session.post(self.__main_url, data=data)

代碼似乎更簡單。
python菜鳥,請(qǐng)各路大神指教

回答
編輯回答
礙你眼

這個(gè)和正則表達(dá)式有關(guān)。在網(wǎng)頁中找到然后匹配一下就可以啦!

2018年9月14日 19:24