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
"
;
}
}
查看全文
相关阅读:
修复ecshop商品重量BUG小数位增至五位
ECSHOP 支付宝发货确认接口,记录支付宝返回的交易号
php数字补零的两种方法
PHP获取当前时间的毫秒数(yyyyMMddHHmmssSSS)
ajax 设置Access-Control-Allow-Origin实现跨域访问
MySQL Master High Available 源码篇
MHA 报错:There is no alive slave. We can't do failover
cdid
mha error
mysql relay log参数汇总
原文地址:https://www.cnblogs.com/songafeng/p/137551.html
最新文章
C#验证子网掩码的正确性
EmguCV控件Emgu.CV.UI.ImageBox及C# picturebox显示图片连续刷新出现闪烁问题
sql优化之not in
UDP 网络通信 C#
UDP SOCKET网络通信 C#
多日期选择jQuery插件 MultiDatesPicker for jQuery UI
syslog日志系统——日志采集
udev example -- detect usb and write test file
libudev使用说明书
(笔记)Linux下的ioctl()函数详解
热门文章
linux下ssh超时时间配置
centos修改ssh默认端口号的方法示例
sudo配置文件/etc/sudoers详解及实战用法
[Linux]权限s权限和t权限
ssh
Linux内核自旋锁spinlock_t机制
Ecshop实现仿Taobao地区运费模板
2015年1月最新中国行政区划县及以上代码mysql数据库
MYSQL 多表更新 UPDATE SET like concat('%',abc,'%');
ecshop订单中配送方式报错
Copyright © 2011-2022 走看看