Categories
Development

How to pull the vedio link name imbeded in a web page along with vedio name

I am trying to pull all the video link reference from the web page along with video names, i have tried below code.

#!/usr/bin/python3
from bs4 import BeautifulSoup
import requests
import urllib
url = urllib.request.urlopen('https://www.ansible.com/resources/videos').read()
acc_link = BeautifulSoup(url, features="lxml")
for line in acc_link.find_all('a'):
    print(line.get('href'))

Output:

https://www.ansible.com/?hsLang=en-us
https://www.ansible.com/overview/it-automation?hsLang=en-us
https://www.ansible.com/overview/it-automation?hsLang=en-us
https://www.ansible.com/overview/how-ansible-works?hsLang=en-us
https://www.ansible.com/products/automation-platform?hsLang=en-us
https://www.ansible.com/use-cases?hsLang=en-us
https://www.ansible.com/use-cases/provisioning?hsLang=en-us
https://www.ansible.com/use-cases/configuration-management?hsLang=en-us
https://www.ansible.com/use-cases/application-deployment?hsLang=en-us
https://www.ansible.com/use-cases/continuous-delivery?hsLang=en-us
https://www.ansible.com/use-cases/security-automation?hsLang=en-us
https://www.ansible.com/use-cases/orchestration?hsLang=en-us
https://www.ansible.com/integrations?hsLang=en-us

HTML source code for example:

<h4><a href="https://www.ansible.com/resources/webinars-training/ansible-network-automation-with-arista-cloudvision-and-arista?hsLang=en-us">Ansible Network Automation with Arista CloudVision and Arista Validated Designs</a></h4>

Like above is just an example for the HTML source code of the link https://www.ansible.com/resources/videos i want link name as https://www.ansible.com/resources/webinars-training/ansible-network-automation-with-arista-cloudvision-and-arista and vedio name Ansible Network Automation with Arista CloudVision and Arista Validated Designs .

Below is just another example where i want href before ? and a value ie Scale-out Clustering with Tower 3.1.

<h4><a href="https://www.ansible.com/scale-out-clustering-tower?hsLang=en-us">Scale-out Clustering with Tower 3.1</a></h4>

Desired output:

Vedio Name: Ansible Network Automation with Arista CloudVision and Arista Validated Designs

Vedio Link: https://www.ansible.com/resources/webinars-training/ansible-network-automation-with-arista-cloudvision-and-arista

Thanks for the help in advanced.

Leave a Reply

Your email address will not be published. Required fields are marked *