本帖最后由 went 于 2021-10-7 11:59 编辑
- #&cls&@cd /d "%~dp0" & powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" &pause&exit
- cls
- #whr
- $whr = New-Object -ComObject 'WinHttp.WinHttpRequest.5.1'
-
- #设置请求头
- function Set-RequestHeader($whr){
- $whr.SetRequestHeader('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Edg/94.0.992.38');
- $whr.SetRequestHeader('Host','www.tvmao.com')
- $whr.SetRequestHeader('Connection','Keep-Alive')
- }
-
- #函数 根据关键字获取url链接
- function Get-Url($kw){
- $url = 'https://www.tvmao.com/servlet/queryobject?type=all&term=' + [System.Net.WebUtility]::UrlEncode($kw)
- $whr.Open('GET',$url,$false)
- Set-RequestHeader -whr $whr
- $whr.Send()
- $txt = $whr.ResponseText
- $whr.Abort()
- if($txt -match '"url":"(.+?)"'){
- return 'https://www.tvmao.com' + $Matches[1] + '/renwuguanxitu'
- }
- return $null
- }
-
- #函数 根据url获取人物关系图
- function Get-GXT($url){
- $whr.Open('GET',$url,$false)
- Set-RequestHeader -whr $whr
- $whr.Send()
- $txt = $whr.ResponseText
- $whr.Abort()
- if($txt -match '(?s)<div class="d_guanxi_img".*?>.*?<img src="(.*?/guanxitu/.*?)"'){
- return $Matches[1]
- }
- return $null
- }
-
- #变量设置
- $cur_file = 'pass.txt' #保存已读取的个数
- $list_file = 'c.txt' #电视剧名称列表文件
- $out_file = 'info.txt' #输出信息文件
- #读取已经解析的个数
- $cur = 0
- if([System.IO.File]::Exists($cur_file)){
- $line = Get-Content $cur_file | Select-Object -First 1
- if($line -match '\d+'){
- $cur = [int]$line
- }
- }
- Write-Host ('上次解析个数: {0}' -f $cur)
- #读取电视剧名称并解析内容
- Get-Content $list_file | Select-Object -Skip $cur | foreach {
- $url = Get-Url -kw $_.Trim()
- if($url -ne $null){
- Write-Host ('正在解析 {0}' -f $_)
- $png_url = Get-GXT -url $url
- if($png_url -eq $null){
- 'nothing'
- } else {
- $info = 'TTT{0}YYY人物关系图: {1}' -f ($_.Trim(),$png_url)
- Out-File -FilePath $out_file -InputObject $info -Append
- }
- Write-Host '--------------------------------------------------'
- Start-Sleep -Milliseconds 500
- }
- ++$cur
- Out-File -FilePath $cur_file -InputObject $cur
- }
复制代码 回复 16# lxh623 |