[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

简单需求 获取关键词搜索结果数量

本帖最后由 zzz1230 于 2022-2-5 02:18 编辑

需求很简单,但是不知道用bat能不能实现
我这里有约5000个关键词,需要用百度学术( https://xueshu.baidu.com/ )或者谷歌学术(https://scholar.google.com.hk/)去搜索关键词,然后记录搜索结果数量。
例如:关键词为cancer,百度学术搜索( https://xueshu.baidu.com/s?wd=cancer ),搜索结果提示“找到约15,600,000条相关结果”,然后记录15600000即可。

不知道价格多少合适,如果可以实现,请大佬自行报价,谢谢!

  1. <#*,:&cls
  2. @echo off
  3. cd /d "%~dp0"
  4. powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
  5. pause
  6. exit /b
  7. #>
  8. # 功能:百度学术记录关键词搜索结果的数量.
  9. # 关键词文件
  10. $srcfile = "words.txt"
  11. # 结果文件
  12. $outfile = "words_out.txt"
  13. # 百度学术
  14. $urlbase = "https://xueshu.baidu.com/s?wd={0}"
  15. $renums = [regex]"找到约(.*)条相关结果"
  16. try {
  17.   $proc = Start-Process -FilePath "iexplore.exe" -ArgumentList "-embedding" -PassThru
  18.   [void]$proc.WaitForInputIdle()
  19. } catch {
  20.   $_ | Write-Host -ForegroundColor Red
  21. } finally {
  22.   $proc.Dispose()
  23. }
  24. $shellApp = New-Object -ComObject Shell.Application
  25. while ($true) {
  26.   $ie = $shellApp.Windows() | Where-Object { $_.FullName -like "*\Internet Explorer\iexplore.exe" -and [string]::IsNullOrEmpty($_.LocationURL) }
  27.   if ($null -ne $ie) {
  28.     break
  29.   }
  30.   Start-Sleep -Milliseconds 200
  31. }
  32. Get-Content -Path $srcfile | ForEach-Object {
  33.   try {
  34.     Write-Host $_ -ForegroundColor Yellow
  35.     $uri = New-Object System.Uri -ArgumentList @(($urlbase -f $_))
  36.     $ie.Navigate($uri.AbsoluteUri)
  37.     while ($ie.Busy) {
  38.       Start-Sleep -Milliseconds 100
  39.     }
  40.     $pso = '' | Select-Object -Property Keyword, ResultCount
  41.     $pso.Keyword = $_
  42.     $node_toolbar = $ie.document.getElementById("toolbar")
  43.     $m = $renums.Match($node_toolbar.innerText)
  44.     if ($m.Success) {
  45.       $pso.ResultCount = [long]$m.Groups[1].Value
  46.     }
  47.     $pso
  48.   } catch {
  49.    
  50.   }
  51. } | Format-Table -AutoSize | Out-File -FilePath $outfile -Encoding utf8
  52. $ie.Quit()
复制代码
微信:flashercs
QQ:49908356

TOP

回复 2# flashercs


    您好,首先非常感谢您的回复。其次,我复制代码后,已经在同一目录下新建了一个words.txt(内有关键词 一行一个),但是测试的时候报错。如图,您看下是什么问题导致的。此外,由于我没有设置预算(因为我也不知道多少合适),您看50元可以吗?如果可以的话,麻烦发下wv或者zfb的收款码,我转给您

TOP

回复 3# zzz1230


    批处理一定要保存为ANSI编码; 我签名有联系方式 qq或wx;
微信:flashercs
QQ:49908356

TOP

返回列表