forked from echoTheLiar/DoubanAuto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautocomment.py
25 lines (23 loc) · 939 Bytes
/
autocomment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: utf-8 -*-
import random
import time
import requests
from lxml import etree
from group import comment
from config import doubanurl
from util import doubanutil
if __name__ == "__main__":
group_id = "beijingzufang"
group_url = doubanurl.DOUBAN_GROUP + group_id
r = requests.get(group_url, cookies=doubanutil.get_cookies())
group_topics_html = etree.HTML(r.text)
group_topics = group_topics_html.xpath(
"//table[@class='olt']/tr/td[@class='title']/a/@href")
group_topics = group_topics[5:]
for topic_url in group_topics:
comment_topic_url = topic_url + "/add_comment#last"
comment_str = "自动帮你顶帖 \n from https://github.com/echoTheLiar/DoubanAuto"
comment_dict = comment.make_comment_dict(topic_url, comment_str)
comment.comment_topic(comment_topic_url, comment_dict)
random_sleep = random.randint(100, 500)
time.sleep(random_sleep)