如何使用提供的代码在所有现有的MS Edge配置文件上自动化Bing搜索查询。

huangapple go评论69阅读模式
英文:

How to automate Bing search queries in all existing profile on MS Edge using code given

问题

以下是您要翻译的代码部分:

for ($a = 0; $a -lt 45; $a++) {
    $RandomWord = Get-Random -InputObject (get-content  C:\Users\ashq4\OneDrive\Documents\RandomwordList.txt)
    $RandomQuestion = Get-Random -InputObject("what+is+","Definition+","Thesaurus+for+","Examples+of+","prefixes+for+","suffixes+for+")
    Start-Process microsoft-edge:http://www.bing.com/search?q=$RandomQuestion$RandomWord -windowStyle Minimized
    start-sleep -Milliseconds 1500
}
start-sleep -Milliseconds 2000
Start-Process microsoft-edge:https://www.bing.com/rewards/dashboard
write-Host Done
Break Script

这段代码用 PowerShell 打开默认的 Microsoft Edge 浏览器,并进行 Bing 搜索,使用来自文本文件的随机搜索词汇。打开 45 个标签页,然后导航到 Bing 奖励仪表板。

以下是对您提供的 AI 代码的翻译:

function Execute-ProfileScript($profileArgument) {
    # 执行 Bing.ps1 脚本 45 次
    for ($j = 0; $j -lt 45; $j++) {
        $RandomWord = Get-Random -InputObject (get-content  C:\Users\ashq4\OneDrive\Documents\RandomwordList.txt)
        $RandomQuestion = Get-Random -InputObject("what+is+","Definition+","Thesaurus+for+","Examples+of+","prefixes+for+","suffixes+for+")
        Start-Process -FilePath "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -ArgumentList "--profile-directory=$profileArgument http://www.bing.com/search?q=$RandomQuestion$RandomWord" -WindowStyle Minimized
        Start-Sleep -Milliseconds 1500
    }

    Start-Sleep -Milliseconds 2000
    Start-Process -FilePath "C:\Program Files (x86)\Microsoft\Edge/Application/msedge.exe" -ArgumentList "--profile-directory=$profileArgument https://www.bing.com/rewards/dashboard"
    Write-Host "Done with $profileArgument"
}

# 获取现有配置文件列表
$edgeUserDataPath = "$env:LOCALAPPDATA\Microsoft\Edge\User Data"
$profiles = Get-ChildItem -Path $edgeUserDataPath -Filter "Profile*" | ForEach-Object { $_.Name }

# 过滤掉 "Default" 配置文件
$profiles = $profiles | Where-Object { $_ -ne "Default" }

foreach ($profileName in $profiles) {
    # 使用指定配置文件打开 Edge
    $profileArgument = "--profile-directory=$profileName"
    Start-Process -FilePath "C:\Program Files (x86)\Microsoft\Edge\Application/msedge.exe" -ArgumentList "$profileArgument --no-first-run --no-default-browser-check --flag-switches-begin --flag-switches-end --site-per-process"

    # 为已打开的配置文件执行脚本
    Execute-ProfileScript -profileArgument $profileArgument
}

这段代码旨在在 Microsoft Edge 浏览器中的多个配置文件中执行搜索任务。它首先获取 Edge 中的现有配置文件列表,然后为每个配置文件执行搜索任务。但是,根据您的描述,它似乎会创建新的配置文件而不是使用现有的配置文件。可能需要进一步检查和调试以解决此问题。

英文:

I was trying to automate Bing search with the following code using PowerShell :

for ($a = 0; $a -lt 45; $a++) {
    $RandomWord = Get-Random -InputObject (get-content  C:\Users\ashq4\OneDrive\Documents\RandomwordList.txt)
    $RandomQuestion = Get-Random -InputObject("what+is+","Definition+","Thesaurus+for+","Examples+of+","prefixes+for+","suffixes+for+")
    Start-Process microsoft-edge:http://www.bing.com/search?q=$RandomQuestion$RandomWord -windowStyle Minimized
    start-sleep -Milliseconds 1500
}
start-sleep -Milliseconds 2000
Start-Process microsoft-edge:https://www.bing.com/rewards/dashboard
write-Host Done
Break Script

This code opens 45 tabs in my default ms edge profile. it uses random search words from a text file.

It works well. My question is how I can open all of my profiles that exist in the Edge browser to perform this automation in separate windows. For example, If I have two profiles. I want the search to happen in each profile with separate two windows carrying out the search automation in 45 tabs each. i.e., 45 tabs in 2 windows respectively.

I asked AI and it provided this:

function Execute-ProfileScript($profileArgument) {
    # Execute the Bing.ps1 script 45 times
    for ($j = 0; $j -lt 45; $j++) {
        $RandomWord = Get-Random -InputObject (get-content  C:\Users\ashq4\OneDrive\Documents\RandomwordList.txt)
        $RandomQuestion = Get-Random -InputObject("what+is+","Definition+","Thesaurus+for+","Examples+of+","prefixes+for+","suffixes+for+")
        Start-Process -FilePath "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -ArgumentList "--profile-directory=$profileArgument http://www.bing.com/search?q=$RandomQuestion$RandomWord" -WindowStyle Minimized
        Start-Sleep -Milliseconds 1500
    }

    Start-Sleep -Milliseconds 2000
    Start-Process -FilePath "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -ArgumentList "--profile-directory=$profileArgument https://www.bing.com/rewards/dashboard"
    Write-Host "Done with $profileArgument"
}

# Get the list of existing profiles
$edgeUserDataPath = "$env:LOCALAPPDATA\Microsoft\Edge\User Data"
$profiles = Get-ChildItem -Path $edgeUserDataPath -Filter "Profile*" | ForEach-Object { $_.Name }

# Filter out the "Default" profile
$profiles = $profiles | Where-Object { $_ -ne "Default" }

foreach ($profileName in $profiles) {
    # Open Edge with the specified profile
    $profileArgument = "--profile-directory=$profileName"
    Start-Process -FilePath "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -ArgumentList "$profileArgument --no-first-run --no-default-browser-check --flag-switches-begin --flag-switches-end --site-per-process"

    # Execute the script for the opened profile
    Execute-ProfileScript -profileArgument $profileArgument
}

It creates new profile its own. Not working as expected but somehow it is opening profiles but creating new ones.

答案1

得分: 1

I found the profile directory:
--profile-directory="Profile $pro"

So It'd be like this:

Start-Process `"msedge`" -ArgumentList `"--profile-directory=`"Profile $pro`"`" https://www.bing.com/search?q=Bing+$_`"

And I'd recommend to randomize the start-sleep part, between 1 and 3 seconds as this:

$rnd = get-random -minimum 1000 -maximum 3000
start-sleep -Milliseconds $rnd
英文:

I found the profile directory:
--profile-directory="Profile $pro"

So It'd be like this:

Start-Process "msedge" -ArgumentList "--profile-directory=`"Profile $pro`" https://www.bing.com/search?q=Bing+$_"

And I'd recommend to randomize the start-sleep part, between 1 and 3 seconds as this:

$rnd = get-random -minimum 1000 -maximum 3000
start-sleep -Milliseconds $rnd

答案2

得分: 0

如果您想使用现有配置文件,请在代码中设置$profileName的值。您可以在*edge://version/*下的配置文件路径中找到配置文件名称。例如,如下图片中的配置文件名称是Default

如何使用提供的代码在所有现有的MS Edge配置文件上自动化Bing搜索查询。

如果您将$profileName = "Default",Edge 将使用该现有配置文件。

英文:

If you want to use the existing profile, just set the $profileName value in the code. You can find the profile name in edge://version/ under Profile path. For example, the profile name is Default in below picture:

如何使用提供的代码在所有现有的MS Edge配置文件上自动化Bing搜索查询。

If you set $profileName = "Default", Edge will open with that existing profile.

huangapple
  • 本文由 发表于 2023年5月29日 18:26:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76356543.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定