Last active
April 2, 2017 14:03
-
-
Save gary-liguoliang/63150f11a14337887657466f028b35bf to your computer and use it in GitHub Desktop.
news.dbanotes.net自动发布脚本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import requests | |
from BeautifulSoup import BeautifulSoup | |
def get_fnid_from_html(html): | |
soup = BeautifulSoup(html) | |
return soup.find("form").find("input").get('value') | |
def publish_news_dbanotes_net(user_id, password, title, url): | |
with requests.Session() as session: | |
response = session.get(r'http://news.dbanotes.net/submit') | |
fnid = get_fnid_from_html(response.text) | |
login_info = { | |
'fnid': fnid, | |
'u': user_id, | |
'p': password | |
} | |
response = session.post('http://news.dbanotes.net/x', data=login_info) | |
fnid = get_fnid_from_html(response.text) | |
submission_details = { | |
'fnid': fnid, | |
't': title[:77] + '...' if len(title) > 80 else title, | |
'u': url, | |
'x': '' | |
} | |
session.post('http://news.dbanotes.net/r', data=submission_details) | |
if __name__ == '__main__': | |
publish_news_dbanotes_net(user-name, password, unicode-title, url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment