Python3 BeautifulSoup爬虫 HDU自动提交
来源:互联网 发布:苗阜精神状态知乎 编辑:程序博客网 时间:2024/05/18 11:28
import http.cookiejarimport loggingimport timeimport urllib.parseimport urllib.requestfrom bs4 import BeautifulSoupfrom submitcode import SubmitCodeclass SubmitHDdu(): def __init__(self, userId, passWord): self.userId = userId self.passWord = passWord cj = http.cookiejar.LWPCookieJar() self.opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) urllib.request.install_opener(self.opener) self.languageMap = {} self.languageMap["Cpp"] = 0 self.languageMap["Java"] = 5 def login(self): params = { "username": self.userId, "userpass": self.passWord, "login": "Sign+In" } loginUrl = "http://acm.hdu.edu.cn/userloginex.php?action=login" postData = urllib.parse.urlencode(params).encode(encoding='UTF8') html = self.opener.open(loginUrl, postData).read() soup = BeautifulSoup(html, "xml") return soup.prettify().find("Sign Out") > -1 def submit(self, pid, language, src): params = { "problemid": pid, "language": self.languageMap.get(language), "usercode": src, "check": 0 } submitUrl = "http://acm.hdu.edu.cn/submit.php?action=submit" postData = urllib.parse.urlencode(params).encode(encoding='UTF8') self.opener.open(submitUrl, postData) def status(self): statusUrl = "http://acm.hdu.edu.cn/status.php?first=&pid=&user=" + self.userId + "&lang=0&status=0" html = urllib.request.urlopen(statusUrl).read() soup = BeautifulSoup(html, "xml") fonts = soup.find_all("font")[2:] trs = soup.find_all("tr")[10:] n = len(trs) for i in range(0, n): contents = trs[i].contents print(contents[1].string.split(">")[1], end="\t") print(contents[2].string, end="\t") print(fonts[i].string.split(">")[1], end="\t") print(contents[4].contents[0].string, end="\t") print(contents[5].string, end="\t") print(contents[6].string, end="\t") print(contents[7].string, end="\t") print(contents[8].string)if __name__ == '__main__': FORMAT = "[ZojAutoSubmit]-----%(message)s------" logging.basicConfig(level=logging.INFO, format=FORMAT) # 用户名 , 密码 (明文) hdu = SubmitHDdu("laoli2009", "123456") if hdu.login(): logging.info("login success!") # hdu.submit("1000", "Cpp", SubmitCode.cppCode) hdu.submit("1000", "Java" , SubmitCode.javaCode) logging.info("submit success!") time.sleep(60) hdu.status() logging.info("search status success!")
阅读全文
0 0
- Python3 BeautifulSoup爬虫 HDU自动提交
- Python3 BeautifulSoup爬虫 POJ自动提交
- Python3 BeautifulSoup爬虫 ZOJ自动提交
- python3 终端下英汉词典 BeautifulSoup+网络爬虫
- python3 终端下英汉词典 BeautifulSoup+网络爬虫
- python3+BeautifulSoup+tkinter 爬虫 获取学校成绩
- beautifulsoup,python3中的爬虫匹配神器
- python3.3 lxml+beautifulsoup 爬虫说明
- Python BeautifulSoup爬虫 HDU题目
- Python3.4 用 BeautifulSoup 爬虫 Navigable String类型转换
- python3实现网络爬虫(2)--BeautifulSoup使用(1)
- python3实现网络爬虫(3)--BeautifulSoup使用(2)
- BeautifulSoup与正则_简单爬虫python3实现
- Python3.6 爬虫初体验--urllib、beautifulsoup(一)
- python3爬虫(三) BeautifulSoup模块的安装和介绍
- Python3爬虫学习笔记(4.BeautifulSoup库详解)
- BeautifulSoup Python3
- 爬虫:BeautifulSoup
- 访问网站出现Access denied for user 'root'@'%' to database 'xxx'
- 区块链基础:散列法(Hashing)
- spring-boot 集成 redis
- 【Android】【bluetooth 】如何记住蓝牙地址名字和状态
- Javascript中bind()方法的使用与实现
- Python3 BeautifulSoup爬虫 HDU自动提交
- 表单控件 文本框 title overall type: UNKNOWN_TYPE server type: NO_SERVER_DATA
- 论 C++ 在OpenJudge中做题的易错点(一)
- opencv3.2的cuda重新编译教程
- SQL Function 自定义函数
- Android中时间、日期的计算方法
- Java正则表达式-基础
- Logrotate操作手册
- web如何制作验证码功能