Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. Sub Test()
  2. Dim bot As New Selenium.WebDriver, lastPage As Integer
  3.  
  4. With bot
  5. .Start "chrome", "http://student.moe.gov.eg/new/index.aspx"
  6. .get "http://student.moe.gov.eg/new/index.aspx"
  7.  
  8. .FindElementById("ctl00_ContentPlaceHolder1_TextBox1").SendKeys "3303364"
  9. .FindElementById("ctl00_ContentPlaceHolder1_TextBox2").SendKeys "33005431"
  10. .FindElementById("ctl00_ContentPlaceHolder1_TextBox3").SendKeys "mypassword"
  11.  
  12. .FindElementById("ctl00_ContentPlaceHolder1_Button2").Click
  13. .FindElementById("ctl00_ContentPlaceHolder1_LinkButton4").Click
  14. .Wait 3000
  15. lastPage = Val(Split(.FindElementByXPath("//div[@class='crtoolbar']//span[contains(.,'/')]").Text, " / ")(1))
  16.  
  17. 'Debug.Print lastPage
  18. Dim ws As Worksheet, cnt As Long, i As Long, j As Long, n As Long
  19. Dim tables As Object
  20. Dim headers(), mappings(), arr(13), newarr(13)
  21.  
  22. cnt = 1
  23. Set ws = ThisWorkbook.Worksheets("Sheet1")
  24. Set tables = .FindElementsByCss("table[width='100%'] table:first-child")
  25.  
  26. '================================
  27. headers = Array("م", "كود الطالب", "الرقم القومي", "اسم الطالب", "الجنسية", "الديانة", "تاريخ الميلاد", "يوم", "شهر", "سنة", "محافظة الميلاد", "حالة القيد", "النوع", "ملاحظات")
  28. mappings = Array(3, 8, 9, 12, 11, 10, 2, 7, 1, 6, 5, 4, 13)
  29. ws.Cells(1, 1).Resize(1, UBound(headers) + 1) = headers
  30.  
  31. For i = 90 To 504 Step 26
  32. arr(0) = vbNullString
  33.  
  34. For j = 0 To 12
  35. arr(mappings(j)) = Application.Trim(tables.Item(i + (2 * (j))).Text)
  36. Next j
  37.  
  38. ' For j = UBound(arr) To LBound(arr) Step -1
  39. ' newarr(n) = arr(j)
  40. ' ' If n = 12 Then
  41. ' ' newarr(n) = CDate(Day(newarr(n)) & "/" & Month(newarr(n)) & "/" & Year(newarr(n)))
  42. ' ' End If
  43. ' n = n + 1
  44. ' Next j
  45.  
  46. ws.Cells(cnt + 1, 1).Resize(1, UBound(arr) + 1) = arr
  47. cnt = cnt + 1: n = 0
  48. Next i
  49.  
  50. '================================
  51.  
  52.  
  53. ' Dim tbl As Selenium.TableElement
  54. '
  55. ' Set tbl = .FindElementById("Table1").AsTable
  56. '
  57. ' 'Print To Excel
  58. ' tbl.ToExcel ThisWorkbook.Sheets("Sheet1").Range("A1")
  59.  
  60.  
  61.  
  62. Stop
  63.  
  64. End With
  65. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement