title author date CreateTime categories
win10 uwp 开发 CSDN 访问量统计 源代码
lindexi
2019-6-23 11:2:1 +0800
2018-2-13 17:23:3 +0800
Win10 UWP

我想得到我CSDN博客的阅读量,那么我应该做一个软件,这个软件可以查看当前的 csdn 博客访问量

界面

启动界面

启动完成输入需要统计的博客的网址

代码

看界面很简单,就一个List做的

主要技术是爬虫

我们先做一个TextBox放博客地址

            <TextBox Margin="10,10,10,10" Header="博客地址" PlaceholderText="http://blog.csdn.net/lindexi_gd" Text="{x:Bind view.PostCsdn.Url,Mode=TwoWay}"></TextBox>

我们还需要类Post存放我们的博客

    public class Post : NotifyProperty
{
public Post()
{ } /// <summary>
/// 阅读数
/// </summary>
public string LinkView
{
set
{
_linkView = value;
OnPropertyChanged();
}
get
{
return _linkView;
}
} public string Original
{
set
{
_original = value;
OnPropertyChanged();
}
get
{
return _original;
}
} /// <summary>
/// 文章
/// </summary>
public string Title
{
set;
get;
} /// <summary>
/// 链接
/// </summary>
public string Url
{
set;
get;
} public string Time
{
set;
get;
} public DateTime LastTime
{
set;
get;
} public int AddView
{
set
{
_addView = value;
OnPropertyChanged();
}
get
{
return _addView;
}
} public List<Scrutiny> ScrutinieCollection
{
set;
get;
}=new List<Scrutiny>(); public void ClonePost(Post post)
{
int postLinkView = int.Parse(post.LinkView);
int linkView = int.Parse(LinkView);
if (postLinkView >= linkView)
{
AddView = postLinkView - linkView;
}
else
{
throw new FormatException();
} LinkView = post.LinkView;
Time = post.Time;
LastTime = post.LastTime;
ScrutinieCollection.Add(new Scrutiny()
{
LinkView = LinkView,
Time = LastTime
});
} private int _addView; private string _linkView;
private string _original;
}

获得csdn的访问量积分等,我们需要得到我们现在所在的页,如果我们在第一页就获取,还获取最大页数,如果我们现在不是第一页就不获取

        private void CompositionOriginal()
{
TotalPost = PostCollection.Count.ToString();
//Original
//var original = PostCollection.Where(temp => temp.Original == "ico ico_type_Original");
var original = PostCollection.Where(temp => temp.Original == "原");
Original = original.Count().ToString();
//Reprint
//var reprint = PostCollection.Where(temp => temp.Original == "ico ico_type_Translated");
var reprint = PostCollection.Where(temp => temp.Original == "转");
Reprint = reprint.Count().ToString();
//Translation
//var translation = PostCollection.Where(temp => temp.Original == "ico ico_type_Repost");
var translation = PostCollection.Where(temp => temp.Original == "翻");
Translation = translation.Count().ToString();
} private void ResponseCallBack(IAsyncResult result)
{
HttpWebRequest http = (HttpWebRequest) result.AsyncState;
WebResponse webResponse = http.EndGetResponse(result);
using (Stream stream = webResponse.GetResponseStream())
{
using (StreamReader read = new StreamReader(stream))
{
string content = read.ReadToEnd();
try
{
UnEncoding(content);
}
catch (Exception e)
{
Debug.Write(e.Message);
}
}
}
} private async void UnEncoding(string content)
{
//<div id="article_list" class="contents"> //</div>\s+<!--显示分页--> //<div id="article_list" class="contents">[^[</div>\s+<!--显示分页-->]]+
Regex regex; if (_maxPage == -1)
{
regex =
new Regex("<div id=\"papelist\" class=\"pagelist\">\\s{0,}<span>\\s{0,}\\d+条\\s{0,}共(\\d+)页</span>");
//<div id="papelist" class="pagelist">
//<span> 109条 共3页</span> //<div id="papelist" class="pagelist">\s{0,}<span>\s{0,}\d+条\s{0,}共(\d+)页</span>
foreach (Match temp in regex.Matches(content))
{
_maxPage = int.Parse(temp.Groups[1].Value);
break;
} //<ul id="blog_rank">
//<li>访问:<span>81372次</span></li>
//<li>积分:<span>2098</span> </li> //<ul id="blog_rank">\s{0,}<li>\s{0,}访问:\s{0,}<span>(\d+)次</span>\s{0,}</li>
//\s{0,}<li>\s{0,}积分:\s{0,}<span>(\d+)</span>\s{0,}</li>
regex = new Regex("<ul id=\"blog_rank\">\\s{0,}<li>\\s{0,}访问:\\s{0,}<span>(\\d+)次</span>\\s{0,}</li>" +
"\\s{0,}<li>\\s{0,}积分:\\s{0,}<span>(\\d+)</span>\\s{0,}</li>");
foreach (Match temp in regex.Matches(content))
{
//_maxPage = int.Parse(temp.Groups[1].Value);
int total = int.Parse(temp.Groups[1].Value);
int integral = int.Parse(temp.Groups[2].Value);
Integral = integral.ToString();
if (!string.IsNullOrEmpty(TotalView) && TotalView != "0")
{
AddView = (total - int.Parse(TotalView)).ToString();
}
TotalView = total.ToString();
}
} regex = new Regex(@"<div id=""article_list"" class=""contents"">([\w|\W]+)</div>\s+<!--显示分页-->");
//<div id="article_list" class="contents">([\w|\W]+)</div>\s+<!--显示分页-->
var match = regex.Matches(content);
foreach (Match temp in match)
{
content = temp.Groups[1].Value;
break;
}
//<div class="list_item list_view">
//<div class="article_title">
//<span class="ico ico_type_Original"></span>
//<h1>
// <span class="link_title"><a href="/lindexi_gd/article/details/51344676">
//C#将dll打包到程序中
//</a></span>
//</h1>
//</div>
//<div class="article_manage">
//<span class="link_postdate">2016-05-29 08:56</span>
//<span class="link_view" title="阅读次数"><a href="/lindexi_gd/article/details/51344676" title="阅读次数">阅读</a>(25)</span> //<div class="list_item list_view">\s{0,}<div class="article_title">\s{0,}
//<span class="ico\s{0,}([\w|_]+)"></span>\s{0,}
//<h1>\s{0,}<span class="link_title"><a href="/([\w|_]+)/article/details/(\d+)">\s{0,}
//(.+)\s{0,}</a></span>
//\s{0,}</h1>\s{0,}
//</div>\s{0,}<div class="article_manage">\s{0,}<span class="link_postdate">(\d+-\d+-\d+ \d+:\d+)</span>\s{0,}
//<span class="link_view" title="阅读次数"><a href="/[\w|_]+/article/details/\d+" title="阅读次数">阅读</a>\((\d+)\)</span>
regex =
new Regex(
"<div class=\"list_item list_view\">\\s{0,}<div class=\"article_title\">\\s{0,}<span class=\"ico\\s{0,}([\\w|_]+)\"></span>\\s{0,}" +
"<h1>\\s{0,}<span class=\"link_title\"><a href=\"/([\\w|_]+)/article/details/(\\d+)\">\\s{0,}" +
"(.+)\\s{0,}</a></span>" +
"\\s{0,}</h1>\\s{0,}" +
"</div>\\s{0,}<div class=\"article_manage\">\\s{0,}<span class=\"link_postdate\">(\\d+-\\d+-\\d+ \\d+:\\d+)</span>\\s{0,}" +
"<span class=\"link_view\" title=\"阅读次数\"><a href=\"/[\\w|_]+/article/details/\\d+\" title=\"阅读次数\">阅读</a>\\((\\d+)\\)</span>");
match = regex.Matches(content); DateTime time = DateTime.Now; //List<Post> post = match.Cast<Match>().Select(temp => new Post()
//{
// Original = temp.Groups[1].Value,
// Url = "/" + temp.Groups[2].Value + "/article/details/" + temp.Groups[3].Value,
// Title = temp.Groups[4].Value.Replace("\r","").Replace("\n","").Trim(),
// Time = temp.Groups[5].Value,
// LinkView = temp.Groups[6].Value,
// AddView = 0,
// LastTime = time
//}).ToList(); List<Post> post = new List<Post>(); foreach (Match temp in match)
{
var original = temp.Groups[1].Value;
var url = "/" + temp.Groups[2].Value + "/article/details/" + temp.Groups[3].Value;
var title = temp.Groups[4].Value.Replace("\r", "").Replace("\n", "").Trim();
var timePost = temp.Groups[5].Value;
var linkView = temp.Groups[6].Value; if (original == "ico_type_Original")
{
original = "原";
}
else if (original == "ico_type_Translated")
{
original = "翻";
}
else
{
original = "转";
} post.Add(new Post()
{
Original = original,
Url = url,
Title = title,
Time = timePost,
LinkView = linkView,
AddView = 0,
LastTime = time
});
} //\s{0,}
await DispatcherPost(post); if (_page == -1)
{
_page = 2;
}
else
{
_page++;
} HttpGet(); //HttpClient client = new HttpClient()
//{
// Timeout = new TimeSpan(1000)
//};
} private async Task DispatcherPost(IEnumerable<Post> post)
{
//var postTitle=PostCollection.Where(temp=>temp.Title==post.Title)
foreach (var temp in post)
{
await DispatcherPost(temp);
}
//await Window.Current.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
// {
// foreach (var temp in post)
// {
// PostCollection.Add(temp);
// }
// });
} private async Task DispatcherPost(Post post)
{
var postTitle = PostCollection.Where(temp => temp.Title == post.Title);
if (postTitle.Any())
{
var temp = postTitle.First();
temp.ClonePost(post);
}
else
{
//await Window.Current.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
//{
// PostCollection.Add(post);
//});
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
PostCollection.Add(post);
});
}
}

现在我使用的方法是 asp dotnet core 通过图片统计 csdn 用户访问

ListView宽度过小

这个问题简单。

                <ListView.ItemContainerStyle>

                    <Style TargetType="ListViewItem">

                        <Setter Property="HorizontalContentAlignment"

                                Value="Stretch"></Setter>

                    </Style>

                </ListView.ItemContainerStyle>

我们可以使用我们的ListView放数据

获取博客

获取博客可以访问网站,获取源码,使用匹配到的数据

我们写软件,一般是用用一个页面来做导航,这个页面就是一个Frame,然后包含各种导航,所以这个页面会一直存在我们的内存。

然后我们需要把MainPage一开始就导航到我们这个页面,我们可以拿到我们的Content,然后把Content给一个Frame,用Frame导航。

        public MainPage()
{
this.InitializeComponent();
Frame frame=Content as Frame;
if (frame == null)
{
frame=new Frame();
Content = frame;
}
frame.Navigate(typeof(View.AssBjPage));
}

if (frame == null)一定会true,因为Content 一般是Grid,我们把content改为Frame

2019-6-23-win10-uwp-开发-CSDN-访问量统计-源代码的更多相关文章

  1. Win10 UWP开发系列:使用VS2015 Update2+ionic开发第一个Cordova App

    安装VS2015 Update2的过程是非常曲折的.还好经过不懈的努力,终于折腾成功了. 如果开发Cordova项目的话,推荐大家用一下ionic这个框架,效果还不错.对于Cordova.PhoneG ...

  2. Win10/UWP开发—使用Cortana语音与App后台Service交互

    上篇文章中我们介绍了使用Cortana调用前台App,不熟悉的移步到:Win10/UWP开发—使用Cortana语音指令与App的前台交互,这篇我们讲讲如何使用Cortana调用App的后台任务,相比 ...

  3. Win10 UWP开发系列:实现Master/Detail布局

    在开发XX新闻的过程中,UI部分使用了Master/Detail(大纲/细节)布局样式.Win10系统中的邮件App就是这种样式,左侧一个列表,右侧是详情页面.关于这种 样式的说明可参看MSDN文档: ...

  4. Win10 UWP开发实现Bing翻译

    微软在WP上的发展从原来的Win7到Win8,Win8.1,到现在的Win10 UWP,什么是UWP,UWP即Windows 10 中的Universal Windows Platform简称.即Wi ...

  5. Win10/UWP开发—凭据保险箱PasswordVault

    PasswordVault用户凭据保险箱其实并不算是Win10的新功能,早在Windows 8.0时代就已经存在了,本文仅仅是介绍在UWP应用中如何使用凭据保险箱进行安全存储和检索用户凭据. 那么什么 ...

  6. Win10/UWP开发—使用Cortana语音指令与App的前台交互

    Win10开发中最具有系统特色的功能点绝对少不了集成Cortana语音指令,其实Cortana语音指令在以前的wp8/8.1时就已经存在了,发展到了Win10,Cortana最明显的进步就是开始支持调 ...

  7. Win10 UWP 开发系列:使用SQLite

    在App开发过程中,肯定需要有一些数据要存储在本地,简单的配置可以序列化后存成文件,比如LocalSettings的方式,或保存在独立存储中.但如果数据多的话,还是需要本地数据库的支持.在UWP开发中 ...

  8. Win10/UWP开发-Ink墨迹书写

    在UWP开发中,微软提供了一个新型的InkCanvas控件用来让用户能书写墨迹,在新版的Edga浏览器中微软自己也用到了该控件使用户很方便的可以在web上做笔记. InkCanvas控件使用很简单,从 ...

  9. Win10 UWP 开发系列:使用多语言工具包让应用支持多语言

    之前我在一篇blog中写过如何使用多语言工具包,见http://www.cnblogs.com/yanxiaodi/p/3800767.html 在WinEcos社区也发布过一篇详细的文章介绍多语言工 ...

  10. Win10/UWP开发—SystemNavigationManager

    Win10系统为确保所有应用中的一致导航体验,提供后退导航功能.当你的应用在手机.平板电脑上或者在支持系统后退功能的电脑或笔记本电脑上运行时,系统会在"后退"按钮被按下时通知你的应 ...

随机推荐

  1. 从pcap文件中分析出数据包

    import dpkt import struct import sys,os f=file(sys.argv[1],"rb") pcap=dpkt.pcap.Reader(f) ...

  2. HDU 6628 permutation 1 (暴力)

    2019 杭电多校 5 1005 题目链接:HDU 6628 比赛链接:2019 Multi-University Training Contest 5 Problem Description A s ...

  3. PAT_A1023#Have Fun with Numbers

    Source: PAT A1023 Have Fun with Numbers (20 分) Description: Notice that the number 123456789 is a 9- ...

  4. 剑指offer——69队列的最大值

    题目: 队列的最大值.请定义一个队列并实现函数max得到队列里的最大值,要求函数max.push_back和pop_front的时间复杂度都是O(1). 题解: 使用队列,操持队列的排序为从大到小的顺 ...

  5. Ubuntu12.04开机自动挂载windows分区

    最近使用Ubuntu12.04时不知到怎么搞的原本能自动识别的Windows的C .D .E盘突然间无法识别了,于是上网搜了一下Ubuntu12.04下自动挂载Windows NTFS分区的方法. 还 ...

  6. springboot上传图片大小限制

    背景:springboot项目上传图片超过1M报错,经了解,springboot默认上传文件1M 需求:更改默认配置,控制上传文件大小 方法:①更改配置文件(经试验不可行,不知道为什么):②更改启动B ...

  7. Mysql 命令行下建立存储过程

    建立存储过程的sql如下: CREATE PROCEDURE  proc_variable () BEGIN DECLARE dec_var_ VARCHAR(100); DECLARE rep_nu ...

  8. D3.js绘制 颜色:RGB、HSL和插值 (V3版本)

    颜色和插值   计算机中的颜色,常用的标准有RGB和HSL.   RGB:色彩模式是通过对红(Red).绿(Green).蓝(Blue)三个颜色通道相互叠加来得到额各式各样的颜色.三个通道的值得范围都 ...

  9. 在IDEA中用Gradle构建项目时使用lombok以依赖出现出错

    情景: 之情一直是使用Maven构建的项目并且导入依赖后都可以正常使用,但是在换成Gradle时出现了不论使用什么版本的lombok的依赖都会提示@Sl4j注解的log找不到,但是编辑界面是不会报错的 ...

  10. Pregel Master