js(javascript)获取网页源码
远程网页源代码读取
/* 页面字体样式 */
body, td, input, textarea {
font-family:Arial;
font-size:12px;
}
//用于创建XMLHttpRequest对象
function createXmlHttp() {
//根据window.XMLHttpRequest对象是否存在使用不同的创建方式
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest(); //FireFox、Opera等浏览器支持的创建方式
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器支持的创建方式
}
}
//直接通过XMLHttpRequest对象获取远程网页源代码
function getSource() {
var url = document.getElementById("url").value; //获取目标地址信息
//地址为空时提示用户输入
if (url == "") {
alert("请输入网页地址。");
return;
}
document.getElementById("source").value = "正在加载……"; //提示正在加载
createXmlHttp(); //创建XMLHttpRequest对象
xmlHttp.onreadystatechange = writeSource; //设置回调函数
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
//www.mp4ku.com将远程网页源代码写入页面文字区域
function writeSource() {
if (xmlHttp.readyState == 4) {
document.getElementById("source").value = xmlHttp.responseText;
}
}
远程网页源代码读取
地址:
delphi动态 WebBrowser 释放问题.rar
delphi动态 WebBrowser 释放问题
var
web:TwebBrowser;
procedure TForm1.Button1Click(Sender: TObject);
begin
web:=TWebBrowser.Create(Self);
web.ParentWindow:=Self.Handle;
web.SetBounds(100,100,100,100);
web.OnDocumentComplete:=WebBrowser1DocumentComplete;
web.Navigate('http://www.3yeah.com/');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
// web.Destroy;
web.Free ;
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
if(web.LocationURL='http://www.qq.com/') then
begin
// web.OnDocumentComplete:=nil;
web.Free;
end;
end;
delphi获取Cookie源码.rar
delphi获取Cookie源码
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool InternetGetCookieEx(string pchUrl, string pchCookieName, StringBuilder pchCookieData,
ref System.UInt32 pcchCookieData, int dwFlags, IntPtr lpReserved);
private static string GetCookieString(string url)
{
uint datasize = 1024;
StringBuilder cookieData = new StringBuilder((int)datasize);
if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x2000, IntPtr.Zero))
{
if (datasize < 0)
return null;
cookieData = new StringBuilder((int)datasize);
if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, IntPtr.Zero))
return null;
}
return cookieData.ToString();
}
private void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
{
richTextBox1.Text = string.Empty;
if (cbcookie.Checked)
{
if (checkBox1.Checked)
{
richTextBox1.Text = GetCookieString(textBox1.Text.Trim());
}
else
{
richTextBox1.Text = webBrowser1.Document.Cookie;
}
}
}
复制代码
//本事件是当每次加载完成当前页面后才会执行的
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//e.Url是当前加载的页面,
if (e.Url.ToString().Contains("http://www.3yeah.com"))
{
//执行操作1
}
else if (e.Url.ToString().Contains("http://baidu.com"))
{
//执行操作2
}
}
复制代码
private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
{
if (cbwindownew.Checked)
{
string url = ((System.Windows.Forms.WebBrowser)sender).StatusText;
webBrowser1.Navigate(url);
e.Cancel = true;
}
}
复制代码