1 Star 0 Fork 0

loveyu/JiaowuHelper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Score.cs 3.90 KB
一键复制 编辑 原始数据 按行查看 历史
loveyu 提交于 2013-12-25 22:41 . Update first to 1.1.0
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace JiaowuHelper
{
class Score
{
Login login;
string url = "";
string postData = "";
Dictionary<int, string> HeaderList;
ArrayList scoreList;
public Score()
{
login = Login.get();
}
public TabPage[] getAll()
{
url = login.homeUrl + "xscjcx.aspx?xh=" + login.id + "&xm=" + login.urlName + "&gnmkdm=N121613";
if (postData == "")
postData = getPostData();
string page = getPostPage(postData);
Url.writeFile(page, "E:\\socre.post.html");
if (parse(page))
{
Dictionary<string, ListView> list = createListView();
TabPage[] tabPages = new TabPage[list.Count];
int i = 0;
foreach (string name in list.Keys)
{
tabPages[i] = new TabPage();
tabPages[i].Text = name;
tabPages[i].Controls.Add(list[name]);
i++;
}
return tabPages;
}
return null;
}
private Dictionary<string, ListView> createListView()
{
Dictionary<string, ListView> dlv = new Dictionary<string, ListView>();
foreach (Dictionary<string, string> list in scoreList)
{
string name = list[HeaderList[0]] + " " + list[HeaderList[1]];
if (!dlv.Keys.Contains(name))
{
ListView lv = new ListView();
lv.View = View.Details;
lv.FullRowSelect = true;
lv.GridLines = true;
foreach (string str in HeaderList.Values)
{
ColumnHeader header1 = new ColumnHeader();
header1.Width = -2;
header1.Text = str;
header1.TextAlign = HorizontalAlignment.Left;
lv.Columns.Add(header1);
}
lv.Dock = DockStyle.Fill;
dlv.Add(name, lv);
}
dlv[name].Items.Add(new ListViewItem(list.Values.ToArray()));
}
return dlv;
}
private string getPostData()
{
string page = Url.readHtml(Url.getPageStream(url));
Url.writeFile(page, "E:\\score.html");
if (page == "") return "";
string rt = "__EVENTTARGET=&__EVENTARGUMENT=&hidLanguage=&ddlXN=&ddlXQ=&ddl_kcxz=&btn_zcj=%C0%FA%C4%EA%B3%C9%BC%A8&__VIEWSTATE=";
Regex reg = new Regex("<input type=\"hidden\" name=\"__VIEWSTATE\" value=\"(.+?)\" />");
Match match = reg.Match(page);
if (match.Value == "") return "";
rt += HttpUtility.UrlEncode(match.Value.Substring("<input type=\"hidden\" name=\"__VIEWSTATE\" value=\"".Length, match.Length - "<input type=\"hidden\" name=\"__VIEWSTATE\" value=\"".Length - "\" />".Length), Encoding.GetEncoding("gb2312"));
return rt;
}
private string getPostPage(string postData)
{
Stream stream = Url.getPostStream(url, postData);
return Url.readHtml(stream);
}
private bool parse(string page)
{
Regex reg = new Regex("<table class=\"datelist\" cellspacing=\"0\" cellpadding=\"3\" border=\"0\" id=\"Datagrid1\" style=\"DISPLAY:block\">(.+?)/table>", RegexOptions.Singleline);
Match match = reg.Match(page);
if (match.Value == "")
{
return false;
}
string rt = Regex.Replace(match.Value, "\\s", "", RegexOptions.Singleline).Replace("</td><td>", "@").Replace("class=\"alt\"", "").Replace("</tr><tr>", "\n");
rt = Regex.Replace(rt, "<(.+?)>", "", RegexOptions.None).Replace("&nbsp;", "");
string[] split = rt.Split('\n');
string[] split2;
bool header = true;
HeaderList = new Dictionary<int, string>();
scoreList = new ArrayList();
try
{
foreach (string tmp in split)
{
split2 = tmp.Split('@');
if (header)
{
for (int i = 0; i < split2.Length; i++)
{
if (split2[i] != "")
HeaderList.Add(i, split2[i]);
}
header = false;
continue;
}
Dictionary<string, string> sc = new Dictionary<string, string>();
foreach (int i in HeaderList.Keys)
{
sc.Add(HeaderList[i], split2[i]);
}
scoreList.Add(sc);
}
}
catch
{
return false;
}
return true;
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/iloveyulove/JiaowuHelper.git
git@gitee.com:iloveyulove/JiaowuHelper.git
iloveyulove
JiaowuHelper
JiaowuHelper
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385