Lấy tin tức từ các trang tin bằng RSS trong powershell

Theo: nguyenhaidang.name.vn | 18/06/2018 - 04:28
cls
 
function  SP_InsertTinTuc_HatGiongTamHon($Title, $Image, $Description, $Detail)
{
    $conn = New-Object system.Data.SqlClient.SqlConnection
    $conn.connectionstring = "server = ....148;Initial Catalog=...dang;User ID=111;Password=111"
   
    #define insert query
    $Command = New-Object System.Data.SQLClient.SQLCommand
    $Command.Connection = $conn
   
    $Command.CommandType = [System.Data.CommandType]::StoredProcedure
    $Command.CommandText = "SP_InsertTinTuc_HatGiongTamHon"
    $Command.Connection = $conn
 
    $Command.Parameters.AddWithValue(''''@Title'''', $Title)
    $Command.Parameters.AddWithValue(''''@Image'''', $Image)
    $Command.Parameters.AddWithValue(''''@Description'''', $Description)
    $Command.Parameters.AddWithValue(''''@Detail'''', $Detail)
 
    $conn.Open()
    $Command.ExecuteNonQuery()# | out-null
    $conn.Close()
    
}
 
[System.Xml.XmlDocument]
 
 
 
    $xml11="";
    $urlss="";
    $inputsNode="";
    $inputsNode1="";
 
    $webclient = New-Object System.Net.WebClient
    $webclient.Encoding = [System.Text.Encoding]::UTF8
    $xml11 = new-object System.Xml.XmlDocument
    $urlss =  [xml]$webclient.DownloadString("https://gacsach.com/rss.xml")
   
    $xml11=$urlss
    $nodelist1 = $xml11.selectnodes("/rss/channel/item")
    foreach ($testCaseNode in $nodelist1) 
    {
      $id = $testCaseNode.getAttribute("title")
      $title = $testCaseNode.selectSingleNode("title").InnerText
      $description = $testCaseNode.selectSingleNode("description").InnerText
      $pubDate = $testCaseNode.selectSingleNode("pubDate").InnerText
      $link = $testCaseNode.selectSingleNode("link").InnerText
      $guid = $testCaseNode.selectSingleNode("guid").InnerText
      #$channel_Id = $testCaseNode.selectSingleNode("channel_Id").InnerText
  
      $destDir = "F:\Images_nguyenhaidang\"+ (Get-Date -Format MM_yyyy).ToString()
      If (!(Test-Path $destDir)) {
         New-Item -Path $destDir -ItemType Directory
      }
      $srcrpatternsrc = ''''(?i)src="(.*?)"''''
      $srcrpatternhref = ''''(?i)href="(.*?)"''''
      $src = ([regex]$srcrpatternsrc ).Matches($description) |  ForEach-Object { $_.Groups[1].Value }
      $href = ([regex]$srcrpatternhref ).Matches($description) |  ForEach-Object { $_.Groups[1].value }
      $string  = $description -split("</br>")
      $content = $string[1]
      $downloadimg = New-Object System.Net.WebClient
      $filename = $src.Substring($src.LastIndexOf("/") + 1)
      $downloadimg.DownloadFile($src,$destDir +"\"+ $filename)
 
      #hien thi cac columns title,description,pubDate,link,guid,channel_Id
      #$destDir +"\"+ $filename
      #$description
      ##content description
          #$filename
          #$href  
          #$content
        SP_Insert_RSS_News -title $title -description $description -deslink $href -desimage $filename -descontain $content -pubDate $pubDate -link $link -guid $guid -urlrss $reader["SiteRSS"]
      
 
 
    }
 

 

Back Head Print
Tin khác

Search GridView with Paging on TextBox KeyPress using jQuery in ASP.Net    (28/07/2010)

Bootstrap AutoComplete TextBox example using jQuery TypeAhead plugin in ASP.Net with C# and VB.Net    (28/07/2010)

Disable Button and Submit button after one click using JavaScript and jQuery    (29/07/2010)

Split and convert Comma Separated (Delimited) String to Table in SQL Server    (01/09/2010)

Select Column values as Comma Separated (Delimited) string in SQL Server using COALESCE    (01/09/2010)