Posted in
Windows Powershell |
No Comment | 15,042 views | 07/06/2009 10:44
This is most exciting post on Powershell for me. Now I’ll get content of a web page and find a user id.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| # Download source code of the web page.
$url = "http://www.yusufozturk.info/wp-content/uploads/2009/06/sample_parse_page.html"
$webclient = new-object System.Net.WebClient
$webpage = $webclient.DownloadString($url)
$webpagetxt = "C:\webpage.timestamp.txt"
$webpage > "$webpagetxt"
# Parse web page and find user id.
$pattern = Select-String "$webpagetxt" -pattern '<a id="rpBasv_hlUserInfo" class="text" href="/user/user_info.aspx'
$pattern = $pattern.get_Line() -replace "\s",""
$userid = $pattern.TrimStart('<td><a id="rpBasv_hlUserInfo" class="text" href="/user/user_info.aspx?uid=')
$userid = $userid.SubString(0,4)
# Show user id
Write-Host User id: $userid |
# Download source code of the web page.
$url = "http://www.yusufozturk.info/wp-content/uploads/2009/06/sample_parse_page.html"
$webclient = new-object System.Net.WebClient
$webpage = $webclient.DownloadString($url)
$webpagetxt = "C:\webpage.timestamp.txt"
$webpage > "$webpagetxt"
# Parse web page and find user id.
$pattern = Select-String "$webpagetxt" -pattern '<a id="rpBasv_hlUserInfo" class="text" href="/user/user_info.aspx'
$pattern = $pattern.get_Line() -replace "\s",""
$userid = $pattern.TrimStart('<td><a id="rpBasv_hlUserInfo" class="text" href="/user/user_info.aspx?uid=')
$userid = $userid.SubString(0,4)
# Show user id
Write-Host User id: $userid
If it works for you, you see user id as “2512”.