Advertisement
ekostadinov

Find information on the subject of your choice

Aug 18th, 2014
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.22 KB | None | 0 0
  1. function GoGoogle($word, $file)
  2. {
  3.     $h3 = "</br><h3 style=""text-align:center;background-color:blue;color:white;""> Google top page results </h3></br>"
  4.  Add-Content $file $h3
  5.     $urlG = 'http://www.google.com//search?q=' + $word + '&cad=h'
  6.     $wreq = Invoke-WebRequest $urlG
  7.     Start-Sleep -Seconds 1
  8.     #get result links div
  9.     $aList = $wreq.Links |where Href -ne $null |select -Property href
  10.     foreach($a in $aList)
  11.     {
  12.         $a = [System.String]$a      
  13.         $dummy = ''      
  14.         for($c=2; $c -le $a.Length - 2; $c++)
  15.         {
  16.             $dummy += $a[$c]
  17.         }
  18.         $dummyStr = ''
  19.         $dummyStr = "</br><a " + $dummy  + ">Google link</a></br>"
  20.         Add-Content $file $dummyStr
  21.     }
  22.     #set back to zero
  23.  $wreq = $null
  24.  $div = $null
  25. }
  26. function GoYoutube($word, $file)
  27. {
  28.     $h3 = "</br><h3 style=""text-align:center;background-color:blue;color:white;""> Youtube top page video results </h3></br>"
  29.  Add-Content $file $h3
  30.     $urlY = 'https://www.youtube.com/results?search_query=' + $word + '+tutorial'
  31.     Start-Sleep -Seconds 1
  32.     #get result links div
  33.     $wreq = Invoke-WebRequest $urlY
  34.     $aList =  $wreq.Links |where title -match $word |select -Property href
  35.     foreach($aLink in $aList)
  36.     {
  37.        $a = [System.String]$aLink
  38.        $a = $a.Insert($a.IndexOf("=") + 1, "http://youtube.com")
  39.        $dummy = ''
  40.        for($c=7; $c -le $a.Length - 2; $c++)
  41.        {
  42.             $dummy += $a[$c]
  43.        }
  44.        $dummy = "</br><a href=""{0}"">Youtube video link</a></br>" -f $dummy
  45.        Add-Content $file $dummy      
  46.     }
  47.     #set back to zero
  48.  $wreq = $null
  49.  $ol = $null    
  50. }
  51. $date = Get-Date
  52. $date = "{0:dd_MM_yyyy}" -f [datetime]$date
  53. $file = 'C:\Users\evgeni.kostadinov\Desktop\webCrawlers\3-webResources\all\results-Google-Youtube-' + $date + '.html'
  54. $db = Get-Content 'C:\Users\evgeni.kostadinov\Desktop\webCrawlers\techsData.txt'
  55. for($k = 0; $k -le $db.Length - 1; $k++)
  56. {
  57.     $searchKeyword = $db[$k]
  58.     $h1 = "<h1 style=""text-align:center;background-color:red;color:white;""> " + $searchKeyword + "</h1>"
  59.  Add-Content $file $h1
  60.     #GoGoogle -word $searchKeyword -file $file
  61.     GoYoutube -word $searchKeyword -file $file
  62. }
  63. start chrome $file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement