17-09-12, 11:05 PM
جمع الروابط و الصور و عرضها في متصفح الانترنت
1. افتح الفيجوال بيسك 2008 (او نسخة الدوت النت التي لديك) ، و اصنع مشروع جديد ، و سمه بالاسم التي تريده (انا سميته image and links grabber)
2. اجعل المشروع كبير ليتحمل الادوات
3. اضف متصفح انترنت سمه (wb) ، و اول زر سمه (btnGo) ، الزر الثاني سمه (btnExtract)
الزر الثالث (btnGetImageSources) ، و مربع نص سمه (txturl) ، و مربع صورة سمه (pic)
و اضف ايضاً قائمة سمها ((LstMain .
صورة اولية
4. تحت كلمةpublic class form1 اكتب هذا الكود
5. اضغط على زر btnGo و اكتب هذا الكود فيه
الان اذا شغلنا البرنامج يجب ان تكتب اسم موقع في مربع النص و تضغط على زر go
6. الان اضغط على زر (btnExtract) و اكتب هذا الكود في داخله
الان شغل البرنامج و اكتب رابط في مربع النص و اضغط زر (Go) و اضغط زر ((Extract وسوف تظهر الروابط الخاصة بالصفحة الحالية لمتصفح الانترنت
7. اضغط على زر (imagesource) و اكتب هذا الكود في داخله
8. الان اكتب هذه الدالة
في اللست البوكس الحدث click اكتب هذا الكود
هذه المقالة من إنشائي
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 a = True Then
a = False
End If
If b = 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 b = True Then
b = False
End If
If a = 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 one) contains .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 PictureBox, ByVal 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 a = True Then
LoadWebImageToPictureBox(pic, lstmain.Text)
End If
If b = True Then
WB.Navigate(lstmain.Text)
End If
هذه المقالة من إنشائي
متغيب قليلاً للدراسة