runxinzhi.com
首页
百度搜索
网页源代码的获取方法
在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
"
;
}
}
相关阅读:
web框架学习
css上
数据库
线程
反射以及部分内置方法
排序函数sort() 和sorted() 之介绍
类的绑定方法
继承
面向对象和类
混淆矩阵、准确率、召回率
原文地址:https://www.cnblogs.com/songafeng/p/137551.html
最新文章
HNU 13074 Goldbach’s Conjecture 解题报告
lombok
VisualVM
数据库主键冲突解决
深入理解Java虚拟机--下
深入理解Java虚拟机--中
深入理解Java虚拟机--上
排序算法
大数据算法
Java随机数和UUID
热门文章
【java并发核心二】Exchanger的使用
Redhat修改主机名及网络配置
【java并发核心一】Semaphore 的使用思路
【python学习-6】异常处理
【python学习-5】面向对象的python
【python学习-4】可复用函数与模块
【python学习-3】python数据类型
【python学习-2】python起步必备
【python学习-1】python环境设置与开发
Linux下多节点SSH无密码互联实现
Copyright © 2020-2023
润新知