是这样的,我在网上也看了一些代码,在github也有,但是有一点我不太懂,我已经成功模拟豆瓣登陆(python 3.5),但在发帖时出了点问题
代码如下
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"] = '好了,发言'
结果会返回
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菜鸟,请大家指教
我看到也有这样写的
data = {
"ck": "NBJ2",
"comment": "模拟登录"
}
session=requests.session()
r = session.post(self.__main_url, data=data)
代码似乎更简单。
python菜鸟,请各路大神指教
这个和正则表达式有关。在网页中找到然后匹配一下就可以啦!