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
"
;
}
}
查看全文
相关阅读:
ArcObject获取ArcMap默认地理数据库的路径
标准IO
进程关系
进程环境
C语言基础知识位运算
Bash 快捷键
信号
UNIX系统文件
进程
unix 文件属性
原文地址:https://www.cnblogs.com/songafeng/p/137551.html
最新文章
SQL SERVER合并值
全部省市县数据库(SQL脚本)以及简单递归查询
nokia n78删除多余无线SSID的方法
使用IP安全策略禁止Ping
JQuery+WebService实现DropDownlist无刷新三级联动
纪念购入6520S两周年
两个月后的今天,一模一样
谷歌时代结束 Google中国名称已经改回
ubuntu安装Discuz
查看数据库的兼容级别
热门文章
决定放弃
discuz X2 +Ubuntu+nginx的伪静态配置
Windows2003 IIS6.0启用Gzip功能
一个男人必须明白的22个道理
数据库主体在该数据库中拥有架构,无法删除解决方法
如何查看端口被什么进程占用
2010.3.13郊野公园小记,以及参观托驼峰航线纪念碑
网页开发中的一些记录
李之仪 <卜算子>
ArcObject获取ArcMap内容列表选中的图层
Copyright © 2011-2022 走看看