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. C++——编译器运行过程

    C++ 编译过程简介   C/C++程序编译流程: 预处理->编译->汇编->链接 具体的就是: 源代码(source coprede)→预处理器(processor)→编译器(co ...

  2. 动态方法调用秘密武器 —— invokedynamic 指令解读 - MethodHandle

    原文:https://juejin.im/book/5c25811a6fb9a049ec6b23ee/section/5ccc66dd518825403b5975fb import java.lang ...

  3. 数据挖掘 FP-tree算法C++实现及源码

    FP-growth挖掘算法 步骤一 扫描数据库,扫描数据库一次,得到频繁1-项集,把项按支持度递减排序,再一次扫描数据库,建立FP-tree 步骤二 对每个项,生成它的 条件模式库 步骤三 用条件模式 ...

  4. Kali Linux 2018 更新源配置

    查看添加更新源 编辑sources.list,将kali更新源加入其中 sudo vim /etc/apt/sources.list 国内更新源 #阿里云 deb http://mirrors.ali ...

  5. C++子类父类构造函数的关系

    在C++中子类继承和调用父类的构造函数方法 构造方法用来初始化类的对象,与父类的其它成员不同,它不能被子类继承(子类可以继承父类所有的成员变量和成员方法,但不继承父类的构造方法).因此,在创建子类对象 ...

  6. 0 ‘+new Array(017)’ 输出? js+相当于Number()类型转换

    网站搬迁,给你带来的不便敬请谅解! http://www.suanliutudousi.com/2017/10/20/new-array017-%E8%BE%93%E5%87%BA%EF%BC%9F- ...

  7. 由dubbo开始看看所谓的软负载均衡

    待总结 我们在微服务架构中,常用一些注册中心进行订阅消费我们的服务,这时候对于同一服务请求会有不同的机器同时可以提供服务,这时是怎么选择哪一台机器去连接获取服务呢? 负载均衡设备作为纵跨网络2/7层交 ...

  8. git config配置,工作区和版本库联系。

    关于git和github的介绍,我这边不多说. 使用在windows下使用git,需要配置环境变量,也可以使用git自带的终端工具.,打开git bash laoni@DESKTOP-TPPLHIB ...

  9. Unity Shader后处理-搜索灰度效果

    如U3D中Hierarchy面板下的搜索效果: 讲解分析: 1.这种PostEffect效果其实就是指Unity shader的后处理,即游戏中实现屏幕特效的常见方法.顾名思义屏幕后处理就是指在渲染完 ...

  10. Django学习铺垫

    Web框架本质 所有的web服务本质都是一个socket服务端,用户浏览器就是一个socket客户端,这样就实现了自己的web框架 ,但是自己的写的框架肯定很low,各种工能崩溃,所以我们就要学习py ...