منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
جمع الروابط و الصور و عرضها في متصفح الانترنت - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغة الفيجوال بيسك VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=182)
+--- قسم : قسم مقالات VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=184)
+--- الموضوع : جمع الروابط و الصور و عرضها في متصفح الانترنت (/showthread.php?tid=4187)



جمع الروابط و الصور و عرضها في متصفح الانترنت - Blue Sky - 17-09-12

جمع الروابط و الصور و عرضها في متصفح الانترنت

1. افتح الفيجوال بيسك 2008 (او نسخة الدوت النت التي لديك) ، و اصنع مشروع جديد ، و سمه بالاسم التي تريده (انا سميته image and links grabber)

2. اجعل المشروع كبير ليتحمل الادوات

3. اضف متصفح انترنت سمه (wb) ، و اول زر سمه (btnGo) ، الزر الثاني سمه (btnExtract)
الزر الثالث (btnGetImageSources) ، و مربع نص سمه (txturl) ، و مربع صورة سمه (pic)
و اضف ايضاً قائمة سمها ((LstMain .

صورة اولية



4. تحت كلمةpublic class form1 اكتب هذا الكود


PHP كود :
Dim a As Boolean 
    Dim b 
As Boolean 

5. اضغط على زر btnGo و اكتب هذا الكود فيه

PHP كود :
WB.Navigate(TxtURL.Text

الان اذا شغلنا البرنامج يجب ان تكتب اسم موقع في مربع النص و تضغط على زر go


6. الان اضغط على زر (btnExtract) و اكتب هذا الكود في داخله
PHP كود :
lstmain.Items.Clear() 
        If 
True Then 
            a 
False 
        End 
If 
        If 
False Then 
            b 
True 
        End 
If 
        
'For every link in the current document...           
        For Each ele As HtmlElement In WB.Document.Links 
            '
Get whatever text there is in the 'href' attribute  
            Dim eletarget 
As String ele.GetAttribute("href"
            
'Add it to the listbox  
            LstMain.Items.Add(eletarget) 
            '
Carry on to the next link  
        Next 


الان شغل البرنامج و اكتب رابط في مربع النص و اضغط زر (Go) و اضغط زر ((Extract وسوف تظهر الروابط الخاصة بالصفحة الحالية لمتصفح الانترنت

7. اضغط على زر (imagesource) و اكتب هذا الكود في داخله
PHP كود :
lstmain.Items.Clear() 
        If 
True Then 
            b 
False 
        End 
If 
        If 
False Then 
            a 
True 
        End 
If 
        
'For every HtmlElement (such as a textbox, a button, or image) in the current document...    
        For Each ele As HtmlElement In WB.Document.All 
            '
Make sure it's an image... rather crude but works...  
            If ele.GetAttribute("src") Is Nothing = True Then 
                '
Do nothing  
            
Else 
                
'Its an image  
                '
If the source of the element (assuming there is onecontains .jpg  
                
If ele.GetAttribute("src").ToLower.Contains(".jpg"Then 
                    
'Declare the source of the image as a string (not really neccesary)  
                    Dim imgsrc As String = ele.GetAttribute("src") 
                    '
Add the string to the listbox  
                    LstMain
.Items.Add(imgsrc
                
End If 

                If 
ele.GetAttribute("src").ToLower.Contains(".png"Then 
                    
'Declare the source of the image as a string (not really neccesary)  
                    Dim imgsrc As String = ele.GetAttribute("src") 
                    '
Add the string to the listbox  
                    LstMain
.Items.Add(imgsrc
                
End If 

                If 
ele.GetAttribute("src").ToLower.Contains(".gif"Then 
                    
'Declare the source of the image as a string (not really neccesary)  
                    Dim imgsrc As String = ele.GetAttribute("src") 
                    '
Add the string to the listbox  
                    LstMain
.Items.Add(imgsrc
                
End If 

                If 
ele.GetAttribute("src").ToLower.Contains(".bmp"Then 
                    
'Declare the source of the image as a string (not really neccesary)  
                    Dim imgsrc As String = ele.GetAttribute("src") 
                    '
Add the string to the listbox  
                    LstMain
.Items.Add(imgsrc
                
End If 
            
End If 
        
Next 

8. الان اكتب هذه الدالة

PHP كود :
Imports System.IO 
Imports System
.Net 
Public Function LoadWebImageToPictureBox(ByVal pb _ 
      
As PictureBoxByVal ImageURL As String) As Boolean 

        Dim objImage 
As MemoryStream 
        Dim objwebClient 
As WebClient 
        Dim sURL 
As String Trim(ImageURL
        
Dim bAns As Boolean 
        
Try 
            If 
Not sURL.ToLower().StartsWith("http://"
                 Then sURL 
"http://" sURL 
            objwebClient 
= New WebClient() 

            
objImage = New  
               MemoryStream
(objwebClient.DownloadData(sURL)) 
            
pb.Image Image.FromStream(objImage
            
bAns True 
        
Catch ex As Exception 
            bAns 
False 
        End 
Try 
        Return 
bAns 
    End 
Function 

في اللست البوكس الحدث click اكتب هذا الكود

PHP كود :
If True Then 
            LoadWebImageToPictureBox
(piclstmain.Text
        
End If 
        If 
True Then 
            WB
.Navigate(lstmain.Text
        
End If 


هذه المقالة من إنشائي


جمع الروابط و الصور و عرضها في متصفح الانترنت - m.sami.ak - 20-09-12

بارك الله فيك


جمع الروابط و الصور و عرضها في متصفح الانترنت - Blue Sky - 20-09-12

و فيك اخي Smile