如何快捷的收集活动帖子做成汇总?做版主的请进。

n
nearby
楼主 (文学城)

应妖妹邀请,虎哥将这个程序修改,打出来的正是妖妹需要的格式。妖妹别怕,绝不能手动收集活动帖子,辛苦得要命。使用这个修改后的python程序,活动帖子的收集基本全自动.
 
You can copy/paste the codes below into a Python program.  If you have Python 3 installed on your computer, you can then follow the prompted instructions to make 活动帖子的收集基本全自动.  
 
庆贺妖妹的活动大获成功!

 

# Author: 书香之家版主 nearby, March 2022 # # Usage of this Python program: # 0. Make sure that you have Internet access and Python 3 installed on your computer (or use Cloud)! # 1. Place this file in a folder. Say, in a folder named "wxc" # 2. Go to your '论坛', search for your '活动' title. You will get one or more pages. Remember how many pages there are. # If you do not know how to do this, just skip this step, I will then assume that there are 3 pages (150 entries, which is more than usual) # 3. execute this program, you will be prompted (asked for) the name of your activity, and # the number of pages you obtained in step 2 (if you do not know the number of pages, just hit ENTER) # Example: # 春天的畅想 # 3 (or Hit ENTER key) # 4. You will also be prompted for your 论坛's name in alphabets/English. You can look up this in your 论坛. # For example, 书香之家 has the URL https://bbs.wenxuecity.com/sxsj/, so its English name is sxsj. # Other examples include: 美语世界 is mysj, 文化走廊 is culture, 诗词欣赏 is poetry, etc. # 5. The result is stored inside 'wxc/sxzj-out.html'. You can then copy/paste the source code of 'sxzj-out.html' into your WXC new page. Done! # # # Note: By default the entries are organized in reverse chronological order. # Should you need them to be placed in chronological order, please do: # Comment out the statement: mylist.reverse() by placing # in front of it, like: #mylist.reverse() # # import requests notargets = ['跟帖', '输入关键词', '内容查询', 'input name', '当前', '首页', '上一页', '尾页', '下一页'] notargets.append('archive') # This is how SXZJ (书香之家) works. When 无忧 starts an activity, she always marks her activity like this. notargets.append('##活动##') # notargets.append('汇总') def isInside(line, notargets_array): for t in notargets_array: if t in line: return True return False # END # the line looks like <a href="/sxsj/76799.html" target="_blank">【<em>春天的畅想</em>】春天属于女人</a> # I need it to be <a href="https://bbs.wenxuecity.com/sxsj/76799.html" target="_blank">【<em>春天的畅想</em>】春天属于女人</a> def addHttp(line): at = line.split('href="') line2 = '<a href="https://bbs.wenxuecity.com' + at[1] return line2 # END def processOneFile(target, html, mylist): # split the text by newline character to get an array of string all = html.text.split('\n') length = len(all) i = 0 while i < length: line = all[i] if (target in line) and (not isInside(line, notargets)): line = addHttp(line) print(line) i = i + 1 line2 = all[i] # look like: [书香之家] - <strong>WXCTEATIME</strong>(6987 bytes ), need to be WXCTEATIME only line2 = line2.replace('</strong>', '<strong>').split('<strong>')[1] line += " " + line2 mylist.append(line) i = i + 1 # END of FUNCTIONS # ---- main starts here ---- print() print('# Author: 书香之家版主 nearby, March 2022') print() target = input('What is the title of your activity (活动)?: ') pages = 3 # default, means there are maximum 150 entries temp = input('How many pages there are when you search for the activity in WXC? (If you do not know, just Hit ENTER): ') if temp != '': pages = int(temp) subid = 'sxsj' temp = input('What is the name of your 论坛 in English? For example, 书香之家 is sxsj, 美语世界 is mysj, 文化走廊 is culture, 诗词欣赏 is poetry: ') if len(temp) >= 2: subid = temp mylist = [] # this is the output file. html2 = open('sxzj-out.html', 'w', encoding='utf-8') url = 'https://bbs.wenxuecity.com/bbs/archive.php?SubID='+subid+'&pos=bbs&keyword=' + target + '&username=' f = requests.get(url) processOneFile(target, f, mylist) for i in range(1, pages): url = 'https://bbs.wenxuecity.com/bbs/archive.php?page=' + str(i) + '&SubID=' + subid +'&pos=bbs&keyword=' + target + '&username=' f = requests.get(url) processOneFile(target, f, mylist) mylist.reverse() for li in mylist: html2.write("<p>" + li+"\n") html2.close() print("\n") print(str(len(mylist)) + " entries") print("\n") print("Please check the file sxzj-out.html. The result is in it! Thanks for using this program. ---- 虎哥 / Nearby ")
妖妖灵
哇!虎哥真是做了一件利城利坛利民的大好事!:)这会省多少时间和精力啊!辛苦大大哒!!!
n
nearby
也谢谢妖妹!祝好!
妖妖灵
人脑把电脑指挥得如此强大,难怪CS火得一塌糊涂:)真心感谢虎哥,雪中送炭:)