0

我有 VB 代码去 Google,填写搜索栏,然后点击搜索按钮。有没有办法让我的程序在搜索后选择特定结果?IE。我搜索“奶酪”,我希望我的程序选择倒数第二个结果(在这种情况下,它是 wwww.chuckecheese.com)

4

3 回答 3

0

我最终使用 Sendkeys 来模拟键盘上的选项卡和向下箭头键。然后,您可以使用这 2 个键导航到所需的搜索结果

于 2013-01-09T02:01:31.723 回答
0

或者您可以绕过使用 API 并使用语音识别来避免广告或成本以改进您的听写搜索。如果您不跳出框框思考并创新自己的解决方案,那么编程就不是编程。编码伴随着创造力,如果你不尝试,你将不知道那是什么。这个网站非常适合这个目的,许多人为编码创新做出了贡献。您必须将一个文本文件添加到您的项目中并随意调用它,然后将代码中的以下路径更改为您自己的路径。文本文件保持空白。该程序会将您的语音搜索写入文件,然后执行搜索,不断覆盖自身。出于某种奇怪的原因,这种方法极大地改进了语音识别和听写的融合。您可以说出整个短语,它会进行搜索。一个好的麦克风是必须的,并且说话清晰,没有背景干扰。

Imports System.Speech.Recognition

'Declarations:
Private ReadOnly Drone As New SpeechRecognitionEngine()

Private ReadOnly Qa As New DictationGrammar()

  Private Sub Form1_Load(sender As Object,
                           e As EventArgs) Handles MyBase.Load
      
       'Dictation Mode | Google Engine
        Drone.LoadGrammarAsync(Qa)
        Drone.RequestRecognizerUpdate()
        Drone.SetInputToDefaultAudioDevice()
        Drone.InitialSilenceTimeout = TimeSpan.FromSeconds(2.5)
        Drone.BabbleTimeout = TimeSpan.FromSeconds(1.5)
        Drone.EndSilenceTimeout = TimeSpan.FromSeconds(1.2)
        Drone.EndSilenceTimeoutAmbiguous = TimeSpan.FromSeconds(1.5)
        AddHandler Drone.SpeechRecognized, AddressOf Drone_SpeechRecognized
        Drone.RecognizeAsync(RecognizeMode.Multiple)

    End Sub

 Private Sub Drone_SpeechRecognized(sender As Object, e As SpeechRecognizedEventArgs)
        Dim google As String = e.Result.Text.ToString

        Select Case (google)
            Case google

                If google <> "+" Then
                    'This section will take spoken word, write to file then execute search.
                    Dim sb As New StringBuilder
                    'Be sure to change the text file path below to your path if you are new to this program.
                    sb.AppendLine(google)
                    'Add your own path below here. you can also change google to youtube and conduct youtube searches
File.WriteAllText("C:\Users\justin.ross\source\repos\ScarlettCenturium\Scarlett Centurium\Scarlett Centurium\File.txt", sb.ToString())
                    google = "https://www.google.com/search?q=" & Uri.EscapeUriString(google)
                    Dim proc As New Process()
                    Dim startInfo As New ProcessStartInfo(google)
                    proc.StartInfo = startInfo
                    proc.Start()
                    'This sendkey will close out previous tab on new search
                    SendKeys.Send($"^{{w}}")
                    Return
                End If
        End Select
    End Sub
于 2022-02-26T11:36:34.363 回答
-1

好吧,您可以为此使用google api

转到http://code.google.com/p/google-api-for-dotnet/

下载 GoogleSearchAPI_0.4_alpha.zip

提取它并添加对项目中 dll 文件的引用(在文件夹 .net 2 中)

你可以像这样使用它

首先导入库

Imports Google.API.Search

然后在子或函数中将您的代码作为

    Dim rf As String = "http://www.google.com"
    Dim v As New Google.API.Search.GwebSearchClient(rf)
    Dim result = v.Search(TextBox1.Text, 40)
    ' number (40) is the amount of fetched results ( change it if you want )
     For Each item In result

        If item.Url.Contains("chuckecheese") Then
            '  your code goes here
        End If



    Next
于 2013-05-14T01:15:20.310 回答