- <#*,:&cls
- @echo off
- cd /d "%~dp0"
- powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
- pause
- exit /b
- #>
- # 功能:百度学术记录关键词搜索结果的数量.
-
- # 关键词文件
- $srcfile = "words.txt"
- # 结果文件
- $outfile = "words_out.txt"
- # 百度学术
- $urlbase = "https://xueshu.baidu.com/s?wd={0}"
-
- $renums = [regex]"找到约(.*)条相关结果"
- try {
- $proc = Start-Process -FilePath "iexplore.exe" -ArgumentList "-embedding" -PassThru
- [void]$proc.WaitForInputIdle()
- } catch {
- $_ | Write-Host -ForegroundColor Red
- } finally {
- $proc.Dispose()
- }
- $shellApp = New-Object -ComObject Shell.Application
- while ($true) {
- $ie = $shellApp.Windows() | Where-Object { $_.FullName -like "*\Internet Explorer\iexplore.exe" -and [string]::IsNullOrEmpty($_.LocationURL) }
- if ($null -ne $ie) {
- break
- }
- Start-Sleep -Milliseconds 200
- }
- Get-Content -Path $srcfile | ForEach-Object {
- try {
- Write-Host $_ -ForegroundColor Yellow
- $uri = New-Object System.Uri -ArgumentList @(($urlbase -f $_))
- $ie.Navigate($uri.AbsoluteUri)
- while ($ie.Busy) {
- Start-Sleep -Milliseconds 100
- }
- $pso = '' | Select-Object -Property Keyword, ResultCount
- $pso.Keyword = $_
- $node_toolbar = $ie.document.getElementById("toolbar")
- $m = $renums.Match($node_toolbar.innerText)
- if ($m.Success) {
- $pso.ResultCount = [long]$m.Groups[1].Value
- }
- $pso
- } catch {
-
- }
- } | Format-Table -AutoSize | Out-File -FilePath $outfile -Encoding utf8
- $ie.Quit()
复制代码
|