Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimitryzub/de0088ca1354d9f5f43a366198fd9a26 to your computer and use it in GitHub Desktop.
Save dimitryzub/de0088ca1354d9f5f43a366198fd9a26 to your computer and use it in GitHub Desktop.
from bs4 import BeautifulSoup
import requests, lxml
headers = {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
}
params = {
"q": "somebody toucha my spaghet",
"cc": "us" # language/country of the search
}
html = requests.get('https://www.bing.com/videos/search', params=params, headers=headers)
soup = BeautifulSoup(html.text, 'lxml')
for result in soup.select('.mc_vtvc.b_canvas'):
title = result.select_one('.b_promtxt').text
link = f"https://www.bing.com{result.select_one('.mc_vtvc_link')['href']}"
views = result.select_one('.mc_vtvc_meta_row:nth-child(1) span:nth-child(1)').text
date = result.select_one('.mc_vtvc_meta_row:nth-child(1) span+ span').text
video_platform = result.select_one('.mc_vtvc_meta_row+ .mc_vtvc_meta_row span:nth-child(1)').text
channel_name = result.select_one('.mc_vtvc_meta_row_channel').text
print(f'{title}\n{link}\n{channel_name}\n{video_platform}\n{date}\n{views}\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment