powershell获取商品标题

Posted on 2019-07-13 18:52  努力成长静待花开  阅读(183)  评论(0编辑  收藏  举报

实现效果:

  

实现代码:

function Get-ItemList($page)
{

    $url_login='http://******.***.lcweb03.cn/master_72gs5v'
    $url_info='http://******.***.lcweb03.cn/goods/index?shop_type=1&page='+$page

    $headers = @{
    'Accept'='application/json, text/javascript, */*; q=0.01';
    'User-Agent'='Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36'
    #add cookie 
    'Cookie'='workspaceParam=0%7C1%7Cgoods%2Findex; PHPSESSID=uc3jr6r87oun5pbrljip1lddr9'
    }

    $headers_2 = @{
    'Cookie'='PHPSESSID=uc3jr6r87oun5pbrljip1lddr9'
    }

    $date=@{
    nickname='username';
    password='passworld'
    }
    $null=[void]{Invoke-RestMethod -Uri $url_login -Method Post -Body $date -Headers $headers -SessionVariable session}
    $con=Invoke-RestMethod -Uri $url_info -Method Get -Headers $headers_2 -WebSession $session
            $a=([regex]::Matches($con,'<div class="name-div" title=(.*?)>'))
    $a=[regex]::Matches($con,'<div class="name-div" title=(.*?)>')
    [regex]::Replace($a.groups.GetEnumerator().value,'<div class="name-div" title=(.*?)>','')
}