PIXNET Logo登入

電腦購物天堂

跳到主文

各種商品資訊

部落格全站分類:數位生活

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 5月 16 週一 201118:21
  • [VBA]取出網頁的特定資料


展開/關閉程式碼







Public pURL As String
Public FindLinks As Boolean
Public rRow As Integer


Sub FindURL(sURL As String)
    Dim IE As New InternetExplorer
    Dim oDoc As New MSHTML.HTMLDocument
    Dim oLink As HTMLAnchorElement
    Dim i As Integer
    FindLinks = False
    IE.navigate sURL
    Do While IE.ReadyState <> READYSTATE_COMPLETE
        UrlForm.Label1.Caption = "網頁:" & sURL & "   連線中請稍候......"
        DoEvents
    Loop
    UrlForm.Label1.Caption = ""
    '引用 Document 對象
    Set oDoc = IE.Document
    '列出網頁中的新聞資料
    Call ListTableinnertext(oDoc)
    '獲取以順序排列的HTML 標籤中所有 Links 對象的集合。
    For i = 0 To oDoc.Links.Length - 1
        On Error Resume Next
        '尋找 Links 對象中innerText為"下頁"的標籤
        '因為網站為簡體,而我是使用繁體,所以才會使用 Like "下*"的方法
        '如果是簡體的環境可以直接改成 oDoc.Links(i).innerText="下頁"
        If Len(oDoc.Links(i).innerText) = 2 And oDoc.Links(i).innerText Like "下*" Then
            'href:獲取目標URL(完整網址)
            UrlForm.ListBox1.AddItem oDoc.Links(i).href
            Set oLink = oDoc.Links(i)
            If Not oLink Is Nothing Then
                pURL = oLink.href
                UrlForm.WebBrowser1.navigate pURL
                FindLinks = True
            End If
        End If
    Next i
    If FindLinks = False Then pURL = ""
    Set oDoc = Nothing
    Set IE = Nothing
End Sub


Sub ListTableinnertext(oDoc)
    Dim DocElemsCnt As Integer
    Dim Tbl As Object
    For DocElemsCnt = 0 To oDoc.all.Length - 1
        'tagName:獲取對象的標籤名稱。
        If oDoc.all.Item(DocElemsCnt).tagName = "TABLE" Then
            Set Tbl = oDoc.all.Item(DocElemsCnt)
            '每個網頁有很多TABLE(表格),而要取得資料的TABLE(表格)共有40列, _
             可以利用此特性來取得正確的TABLE(表格)
            If Tbl.Rows.Length > 20 Then
            'Tbl.Rows.Length:取得TABLE(表格)的列數
                For RwLen = 0 To Tbl.Rows.Length - 1
                    rRow = rRow + 1
                    'Int(Tbl.Cells.Length / Tbl.Rows.Length):可取得TABLE(表格)共有幾欄
                    For Colen = 0 To Int(Tbl.Cells.Length / Tbl.Rows.Length) - 1
                        Cells(rRow, Colen + 1).Value = Tbl.Rows(RwLen).Cells(Colen).innerText
                    Next Colen
                Next RwLen
            End If
        End If
    Next DocElemsCnt
    Application.Goto Cells(rRow, 1), Scroll:=True
End Sub


Sub FormShow()
    UrlForm.Show 0
End Sub
 

 




(繼續閱讀...)
文章標籤

pcman 發表在 痞客邦 留言(0) 人氣(4,892)

  • 個人分類:VB
▲top
  • 5月 16 週一 201116:44
  • [VB]WebBrowser.ObjectForScripting




使用WebBrowser 控件,可以通過 ObjectForScripting 和Document 
屬性在客戶端應用程序代碼和網頁腳本代碼之間實現雙向通信


'宣告

Public Property ObjectForScripting As Object



'用途
Dim instance As WebBrowser
Dim value As Object
value = instance.ObjectForScripting
instance.ObjectForScripting = value


(繼續閱讀...)
文章標籤

pcman 發表在 痞客邦 留言(0) 人氣(588)

  • 個人分類:VB
▲top
  • 5月 16 週一 201116:42
  • [C#]JavaScript與C# Windows應用程序交互

一、建立網頁
<html>
<head>
       <meta http-equiv="Content-Language" content="zh-cn">
       <script language="javascript" type="text/javascript">
              
<!-- 提供給C#程序調用的方法 -->
              
function messageBox(message)
              
{
                    alert(message);
             }

       
</script>
</head>
<body>
       <!-- 調用C#方法 -->
       <button onclick="window.external.MyMessageBox('javascript訪問C#代碼')" >
       javascript訪問C#代碼</button>
</body>
</html>
(繼續閱讀...)
文章標籤

pcman 發表在 痞客邦 留言(0) 人氣(1,138)

  • 個人分類:VB
▲top
  • 5月 16 週一 201116:15
  • [VB]webbrowser 控件實現WinForm與WebForm交互



WebBrowser 控件可以讓你裝載Windows Form 應用程序中的 Web 網頁和其它採用瀏覽器的文件。可以使用webbrowser 控件將現有的web框架控制項加入至 Windows Form 客戶端應用程序。



還是直接看代碼吧。


WebBrowser 控制項 提供的屬性、方法和事件,可用來實現 Internet Explorer 的控制項
webBrowser1.Navigate(
"www.cnblogs.com"); //將指定位置處的文件載入至 WebBrowser
webBrowser1.GoBack();//上一頁
webBrowser1.GoForward();//下一頁
webBrowser1.Refresh();//刷新
webBrowser1.GoHome();//主頁
這裡提供了WebBrowser常用的方法,



上面的代碼是將 我們園子的主頁載入到WebBrowser控件中。如果我們想要在應用程式中產生自己的網頁內容,可以設定DocumentText屬性。也可以通過Document屬性來處理目前的網頁內容。如下代碼是使用DocumentText 屬性,顯示網頁內容。並用Document屬性來處理所顯示的網頁。

 



private void btnDocumentText_Click(object sender, EventArgs e)
{
string szHtml = @"
<HTML>
<HEAD>
<TITLE> DocumentText </TITLE>
</HEAD>
<BODY>
Please enter your name:<br/>
<input type='text' name='Name'/><br/>
<a href='http://www.microsoft.com' >Send input to method of Form class</a>
</BODY>
</HTML>
";
webBrowser1.DocumentText
= szHtml;
}
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
System.Windows.Forms.HtmlDocument document
= this.webBrowser1.Document;
if (document != null && document.All["Name"] != null && String.IsNullOrEmpty(document.All["Name"].GetAttribute("value")))
{
e.Cancel
= true;
System.Windows.Forms.MessageBox.Show(
"You must enter your name before you can navigate to " + e.Url.ToString());
}
}



既然我們可以通過DocumentText生成自己的網頁,那麼能不能像使用IE那樣操作這個網頁呢?,答案是肯定的,完全可以像操作Web程序那樣操作WebBrowser 控制項。比如我們可以加入腳本,CSS。當然,如果你熟悉 HTML 物件對像模型 (DOM),也可以透過 Document 屬性來處理目前的Web網頁內容。下面的例子加入了JavaScript腳本來控制網頁。如果要在Winfrom程序中寫大量的Javascriot代碼,而且這些代碼最終要轉換成String型載入到Webbrowser 那將是很痛苦的事情,不過沒有關係,我們可以創建一個js文件,放入資源中,用的時候只需從資源中載入即可。這裡我創建一個名為 ClientScript.js 的文件



<script language = "javascript">
function ClickEvent(name)
{
alert(
"Hello: " +name);
}
function KeyDown()
{
if (event.keyCode==116)
{
event.keyCode=0;
event.returnValue=false;
}
return false;
}







string szClientScript = ManagedWebBrowser.Properties.Resources.ResourceManager.GetString("ClientScript");
string szWebBrowserText = "<html>" +
"<head>" +
"<title></title>" +
szClientScript
+
"</head>" +
"<body onkeydown=\"KeyDown()\" oncontextmenu=\"event.returnValue=false\">" +
"Please enter your name:<br/>" +
"<input type='text' name='Name'/><br/>" +
"<font onclick = 'ClickEvent(Name.value)'>Click Here</font>" +
"</body></html>";
webBrowser1.DocumentText
= szWebBrowserText;




WebBrowser 是 System.Windows.Forms 下的控制項,也就是意味著它是用在WimForm程序下,那麼WebWrower所載入的Web頁面如何實現在WinForm程序下處理呢。例如上例中的 "Click Here" 。這裡的Click事件是通過腳本處理的,如何讓這個Click事件在Winform中處理呢?這裡要做一些修改。若要從指令碼存取用戶端應用程式,需要設定ObjectForScripting屬性。指令碼可以將您指定的物件當做window.external 物件來存取。
使用ObjectForScripting屬性,可啟用 WebBrowser 控制項所裝載之 Web 網頁與包含 WebBrowser 控制項之應用程式間的通訊。
這個屬性可讓您整合動態超文字標記語言 (DHTML) 程式碼與用戶端應用程式程式碼。
指定給這個屬性的物件可讓 Web 網頁指令碼做為 window.external 物件,這個物件是為了存取主應用程式而提供的內建 DOM 物件。



private void btnScriptEvent_Click(object sender, EventArgs e)
{
// This is the handler for loading the script into the Web Browser control and allowing us to interact
// between the script in the Browser control and this form class
// Set the ObjectForScripting property of the Web Browser control to point to this form class
// This will allow us to interact with methods in this form class via the window.external property
webBrowser1.ObjectForScripting = this;
string szWebBrowserText = "<html>" +
"<head>" +
"<title></title>" +
"</head>" +
"<body onkeydown=\"KeyDown()\" oncontextmenu=\"event.returnValue=false\">" +
"Please enter your name:<br/>" +
"<input type='text' name='Name'/><br/>" +
"<font onClick='window.external.ClickEvent(Name.value)'>Click Here</font>" +
"</body></html>";
webBrowser1.DocumentText
= szWebBrowserText;
}
public void ClickEvent(string userName)
{
// Simply echo out the name that the user typed in the input box of the HTML page
if (System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft == true)
MessageBox.Show(
"Hello " + userName, "Managed Web Browser Sample", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
else
MessageBox.Show(
"Hello " + userName, "Managed Web Browser Sample", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
}




這裡的ObjectForScripting 屬性設置為 this。注意:在From1 類的開頭加入了這麼一句[ComVisible(true)], 它在System.Runtime.InteropServices下,預設值為 true,指出 Managed 型別對於 COM 為可見的。
 [ComVisible(true)]
 public partial class Form1 : System.Windows.Forms.Form
結束語:
本文簡單的介紹了 WebBrowser 的用法,實現了WinForm程序下與Web頁面的交互使用。本人在院子裡一直以來都是看客,這是第一次在園子裡留下技術足跡。有不妥之處,還望各位朋友指正。
感謝您能看到這裡。



綠色通道:好文要頂關注我收藏該文與我聯繫











 



 







(繼續閱讀...)
文章標籤

pcman 發表在 痞客邦 留言(0) 人氣(3,791)

  • 個人分類:VB
▲top
  • 5月 16 週一 201116:11
  • [VB] WebBrowser 判斷該網頁己被下載完成

問:
請問一下 我用 WebBrowser 的控制項設計一Browser,我想知道如何判斷該網頁己被瀏覽器下載完成?
答:
當網頁下載完成時,便會觸發webbrowser1_navigatecomplete2的事件!!!
(繼續閱讀...)
文章標籤

pcman 發表在 痞客邦 留言(0) 人氣(390)

  • 個人分類:VB
▲top
  • 5月 16 週一 201115:31
  • [linux]Kernel使用的資料結構


1.記 憶 體 配 置 、 釋 放 和 轉 移

void *kmalloc(unsigned int size, int priority)
void *kfree_s(void * obj, int size)
kfree(char *)
memcpy_fromfs(dest, src, size)
memcpy_tofs(dest, src, size)
put_fs_byte(src, dest)
byte get_fs_byte(char *s)
(繼續閱讀...)
文章標籤

pcman 發表在 痞客邦 留言(0) 人氣(1,245)

  • 個人分類:LINUX
▲top
  • 5月 16 週一 201115:12
  • [linux]Block Device Driver和 Character Device Driver

Block Device Driver是 以 固 定 大 小 長 度 來 傳 送 轉 移 資 料
Character Device Driver是 以 不 定 長 度 的 字 元 傳 送 資 料 。
(繼續閱讀...)
文章標籤

pcman 發表在 痞客邦 留言(0) 人氣(2,287)

  • 個人分類:LINUX
▲top
  • 5月 13 週五 201116:59
  • [linux]QEMU

QEMU 是一套 emulator 軟體,能在 PC 系統上模擬其他 processor 的運作方式,在 Linux 或 Windows 上都能執行。
QEMU 的相關介紹可參考維基百科或是其官方網站 

[5]
http://en.wikipedia.org/wiki/Emulator

(繼續閱讀...)
文章標籤

pcman 發表在 痞客邦 留言(0) 人氣(173)

  • 個人分類:LINUX
▲top
  • 5月 13 週五 201116:52
  • [linux]將 driver 掛載到 kernel 上


方法一:用 module 的方式撰寫 driver
將 driver 製作成 module 的好處是可以在不重開機的狀下,重複載入更新過的 driver ,在開發 driver 時是一個方便的許選擇。
在編譯 module 前,要先更新 ubuntu 的套件。請在終端機下鍵入:
sudo apt-get install module-assistant

1.調整 kernel 為接受 module


因為原本預設的 kernel config 並不接受動態掛載 module ,我們要新增對 loadable module 的支援。


首先找到在實驗二中所使用的 linux kernel 原始碼,接著在的 menuconfig 中 [3]
,找到 「 Loadable Module Support 」,並將它裡面的 「 Enable loadable module support
」、「 Module unloading 」以及「 Forced module unloading 」勾選為 built-in

,再存檔離開即可。


接著請重新編譯 kernel ,即可產生支援動態掛載 module 的 kernel image 了。










[3] 編譯 linux kernel 的相關步驟可參考實驗二



2 編譯 driver module


編譯 module 的方法和一般的程式有一些不同,請先到 opencsl 網站下載 Makefile :


wget http://opencsl.openfoundry.org/src/Makefile

將它和 demo.c 放到同一層目錄,並在上面鍵入 [4]


make -C <linux> M=$(pwd) modules ARCH=arm CROSS_COMPILE=arm-linux-uclibc-

即可產生 demo.ko ,這是我們之後要拿來掛載的 module 。










[4] <linux> 為 linux source 的根目錄路徑



3 掛載 driver


在 linux 中和 module 有關的指令有三:



  1. insmod : 掛載 module

  2. lsmod : 檢查目前 module 的狀態

  3. rmmod :卸載 module


在用 QEMU 載入新 kernel image 後,可以在 demo.ko 的目錄下鍵入


insmod demo.ko

即可將 demo 載入 kernel 中。此時可用 lsmod 來確定 demo 是否有被成功掛載。


在掛載 demo 的同時,我們也可以發現 linux 有印出我們在 demo.c 裡定義的訊息。


若要將 demo 移除或重新掛載,可以鍵入


rmmod demo.ko

就可以將 demo 移除。



(繼續閱讀...)
文章標籤

pcman 發表在 痞客邦 留言(0) 人氣(16,814)

  • 個人分類:LINUX
▲top
  • 5月 13 週五 201116:50
  • [linux]撰寫 driver 程式


引入標頭檔


在撰寫 driver 前必須先 include 一些標頭檔:


#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>


撰寫控制元件的函式


struct file_operations 即為定義各個 function pointer 的 structure。


static ssize_t drv_read(struct file *filp, char *buf, size_t count, loff_t *ppos)
{
printk("device read\n");
return count;
}
static ssize_t drv_write(struct file *filp, const char *buf, size_t count, loff_t *ppos)
{
printk("device write\n");
return count;
}
static int drv_open(struct inode *inode, struct file *filp)
{
printk("device open\n");
return 0;
}
int drv_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
printk("device ioctl\n");
return 0;
}
static int drv_release(struct inode *inode, struct file *filp)
{
printk("device close\n");
return 0;
}

 struct file_operations 即為定義各個 function pointer 的 structure。
struct file_operations drv_fops =
{
read: drv_read,
write: drv_write,
ioctl: drv_ioctl,
open: drv_open,
release: drv_release,
};

撰寫初始化、結束元件的函式


#define MAJOR_NUM 60
#define MODULE_NAME "DEMO"
static int demo_init(void) {
if (register_chrdev(MAJOR_NUM, "demo", &drv_fops) < 0)
{
printk("<1>%s: can't get major %d\n", MODULE_NAME, MAJOR_NUM);
return (-EBUSY);
}
printk("<1>%s: started\n", MODULE_NAME);
return 0;
}
static void demo_exit(void) {
unregister_chrdev(MAJOR_NUM, "demo");
printk("<1>%s: removed\n", MODULE_NAME);
}
module_init(demo_init);
module_exit(demo_exit);

其中 MAJOR_NUM 即為 driver 所對應的 device 的 major number


(繼續閱讀...)
文章標籤

pcman 發表在 痞客邦 留言(0) 人氣(1,043)

  • 個人分類:LINUX
▲top
12...6»

GTV 大視界

文章分類

toggle OS (2)
  • LINUX (13)
  • Andriod (1)
toggle 案件 (1)
  • 嵌入式系統 (0)
toggle 電子電路 (1)
  • 顯示器 (1)
toggle 程式語言 (1)
  • VB (24)
toggle 流行女裝 (2)
  • 白鳥花子 (0)
  • 天母嚴選 (0)
  • 硬碟 (1)
  • 處理器 (2)
  • 顯示卡 (5)
  • 喇叭音效 (1)
  • 電源 (1)
  • 螢幕 (5)
  • 未分類文章 (1)

文章搜尋

熱門文章

  • (4,441)[VB][IO]如何存取檔案
  • (4,275)[VB][系統]如何製作延遲時間
  • (2,903)動態對比是什麼
  • (1,697)GUID磁碟分割表
  • (1,549)[VB][網頁]vb.net介面程式自動連線至網頁,並且自動發訊息至手機上
  • (1,017)[VB][網頁]如何抓到網頁中圖片的URL
  • (721)[VB][網路]VB.NET 如何讀取網頁.並自動跳下一頁
  • (665)System Call 與驅動程式的關係
  • (437)[linux]Device File
  • (364)[VB][網路]WebBrowser載入去的網頁如果有捲軸時,自動移到最下頁

最新文章

  • [VBA]取出網頁的特定資料
  • [VB]WebBrowser.ObjectForScripting
  • [C#]JavaScript與C# Windows應用程序交互
  • [VB]webbrowser 控件實現WinForm與WebForm交互
  • [VB] WebBrowser 判斷該網頁己被下載完成
  • [linux]Kernel使用的資料結構
  • [linux]Block Device Driver和 Character Device Driver
  • [linux]QEMU
  • [linux]將 driver 掛載到 kernel 上
  • [linux]撰寫 driver 程式

BloggerADS

最新留言

    文章精選

    VB教學網站

    誰來我家

    參觀人氣

    • 本日人氣:
    • 累積人氣:

    站長工具