zoukankan
html css js c++ java
网页源代码的获取方法
在WinForm里获得一个网页的源代码在有的情况下非常有用,特别是在做外挂的时候。这里用pop为例,讲一下获取的方法,然后顺便通过正则表达式获得用户登陆的验证码。
小程序的演示效果如下:
这段是获取HTML源代码的方法:
private
void
btnShowCode_Click(
object
sender, System.EventArgs e)
{
System.Net.WebRequest myWebRequest
=
System.Net.WebRequest.Create(
this
.txtURL.Text);
myWebRequest.Timeout
=
5000
;
string
_htmlCode
=
""
;
try
{
System.Net.WebResponse myWebR
=
myWebRequest.GetResponse();
System.IO.Stream resStream
=
myWebR.GetResponseStream();
System.IO.StreamReader sr
=
new
System.IO.StreamReader(resStream,System.Text.Encoding.Default);
_htmlCode
=
sr.ReadToEnd();
resStream.Close();
sr.Close();
this
.txtCode.Text
=
_htmlCode;
}
catch
(System.Net.WebException ex)
{
this
.txtCode.Text
=
ex.Message;
}
getValidateCode(_htmlCode);
}
通过正则表达式获得其中用户登陆的验证码:
private
void
getValidateCode(
string
htmlCode)
{
string
pattern
=
@"
[>]\d{4}[<]
"
;
System.Text.RegularExpressions.Regex regex
=
new
System.Text.RegularExpressions.Regex(pattern);
System.Text.RegularExpressions.Match match
=
regex.Match(htmlCode);
if
(match.Success)
{
this
.txtValidateCode.Text
=
match.Value.Substring(
1
,
4
);
}
else
{
this
.txtValidateCode.Text
=
"
null
"
;
}
}
查看全文
相关阅读:
朴素贝叶斯分类器实现
Puppeteer使用
神经网络常用名词
Mysql binlog的基本使用和数据库恢复步骤
webpack之代码分割及页面缓存优化
webpack之常用loader的配置和使用
webpack之常用plugin的配置和使用
第11章 面向对象
第10章 面向对象
第9章 模块与包
原文地址:https://www.cnblogs.com/songafeng/p/137551.html
最新文章
十五周助教总结
十四周助教总结
十三周助教总结
C语言I博客作业07
十二周助教总结
C语言I博客作业05
第十一周助教总结
自记录常用站点
docker pull 镜像很慢的问题
去掉HTML代码 保留文字和图片
热门文章
Nlog 手动配置
docker redis
docker mysql 5.7.31
docker jenkins/jenkins 安装和中文化
docker gitlab 12.3.5ee 安装及汉化 和内存调优记录
.net 数据结构:线性结构、链表、Set容器、Hash散列
redis五大类型
常见分布总结
BNN常用激活函数总结
人工智能发展史
Copyright © 2011-2022 走看看