Search code examples
androidwebviewgoogle-search

How to load video list in webview from google search in android


I am developing video downloader app. where i want to show video list in webview for the search result of user. I have EditTextBox where the user enters search item like Funny video, and then press button, and it should load video list in webview. but currently, i can only show the search result as ALL, not Video. please see attachment. I am using this query for Google search

 webView.loadUrl("https://www.google.com/search?q="+query_string);

Search result i get

Search result I NEED


Solution

  • I just did a few dummy Google searches to find out a plausible solution for this. In these searches, I tried to figure out the URL pattern between 'All' search results and 'Video' results. Suppose our search query is "hello"

    What I found is that for 'All' results page, the simplest URL is this :-

    https://www.google.co.in/search?q=hello

    While, for the same query, the simplest URL for 'Video' results is this :-

    https://www.google.co.in/search?q=hello&source=lnms&tbm=vid

    Therefore, in your Webview query, you could simply replace your existing query with the following in order to show your 'Video' results :-

    webView.loadUrl("https://www.google.co.in/search?q=hello"+query_string+"&source=lnms&tbm=vid");
    

    Though, please note the following things :-

    1. I tested these URLs on Google Chrome, and I do not know if they'd work on browsers such as Safari.
    2. The URLs mentioned above are the simplest representations. The actual URL that are displayed in my browser have more fields.