> ## Content Index
> Fetch the complete content index at: https://serpapi.com/blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# Scrape DuckDuckGo Inline Video Results with Python
- URL: https://serpapi.com/blog/scrape-duckduckgo-inline-video-results-with-python/
- Published: 2021-08-18T16:45:10.000Z
- Updated: 2022-04-18T12:58:13.000Z
- Description: Scrape Inline Images from DuckDuckGo Organic Search using Python.
- Author: Dmitriy Zub
- Tags: DuckDuckGo, Python, Web Scraping

### What will be scraped

![image](https://res.cloudinary.com/practicaldev/image/fetch/s--BtCyi1an--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/41b5wlxqm1mfzs97ih50.png)

### Process

If you read my previous post about scraping [DuckDuckGo organic news results](https://serpapi.com/blog/scrape-duckduckgo-news-results-from-organic-search-with-python/) then you'll find this process very familiar.

Selecting `CSS` selectors for container, title, link, source, date was published, number of views, video duration.  

![](https://i.giphy.com/media/qfFOhAkwljaZuFWpVq/giphy.gif)

### Code

```python
from selenium import webdriver
import re, urllib.parse

driver = webdriver.Chrome(executable_path='path/to/chromedriver.exe')
driver.get('https://duckduckgo.com/?q=elon musk dogecoin&kl=us-en&ia=web')

for result in driver.find_elements_by_css_selector('#m3-0 .has-image'):
    title = result.find_element_by_css_selector('#m3-0 .js-carousel-item-title').text
    link = result.find_element_by_css_selector('#m3-0 .module--carousel__body a').get_attribute('href')
    try:
        views = result.find_element_by_css_selector('#m3-0 .module--carousel__extra-row').text
    except:
        views = None
    try:
        video_duration = result.find_element_by_css_selector('#m3-0 .image-labels__label').text
    except:
        video_duration = None
    date = result.find_element_by_css_selector('#m3-0 .tile__time').text
    platfrom_ = result.find_element_by_css_selector('.module--carousel__gray-text').text
    thumbnail_encoded = result.find_element_by_css_selector('#m3-0 .is-center-image').get_attribute('style')
    # https://regex101.com/r/VjOLjj/1
    match_thumbnail_urls = ''.join(re.findall(r'background-image: url\(\"\/\/external-content\.duckduckgo\.com\/iu\/\?u=(.*)&f=1\"\);', thumbnail_encoded))
    # https://www.kite.com/python/answers/how-to-decode-a-utf-8-url-in-python
    thumbnail = urllib.parse.unquote(match_thumbnail_urls)

    print(f'{title}\n{link}\n{platfrom_}\n{views}\n{date}\n{video_duration}\n{thumbnail}\n')

driver.quit()

---------------
'''
Crypto wallets explained
https://www.cnet.com/news/dogecoin-creator-says-cryptocurrency-is-a-right-wing-funnel-of-profiteering/
CNET
None
1d
3:31
https://tse3.mm.bing.net/th?id=OVF.rxHgqP%2fwOSKJnuTLHnQBjw&pid=Api&h=120
...
'''

```

### [DuckDuckGo Inline Videos API](https://serpapi.com/duckduckgo-inline-videos)

The main thing that needs to be done is to iterate over structured `JSON` string and apply it to your needs rather than coding everything from scratch and figuring out how to deal with problems along the way.

```python
import json
from serpapi import GoogleSearch

params = {
  "engine": "duckduckgo",
  "q": "elon musk dogecoin",
  "kl": "us-en",
  "api_key": "YOUR_API_KEY"
}

search = GoogleSearch(params)
results = search.get_dict()

print(json.dumps(results['inline_videos'], indent=2, ensure_ascii=False))

--------------------------

'''
[
  {
    "position": 1,
    "title": "Is Elon Musk Selling All His Dogecoin For Bitcoin?",
    "link": "https://www.youtube.com/watch?v=smva4ayUxK0",
    "duration": "8:35",
    "platform": "YouTube",
    "date": "2021-07-12T03:06:20.0000000",
    "views": 48350,
    "thumbnail": "https://tse4.mm.bing.net/th?id=OVF.leIgxaS7tGYZAB0etKqMFw&pid=Api"
  }
]
...
'''

```

### Links

[Github Gist](https://gist.github.com/dimitryzub/9cf0e99c1836106cda2cc56527ec54bb) • [DuckDuckGo Inline Videos API](https://serpapi.com/duckduckgo-inline-videos)