Finding src from video tag in a div in BeautifulSoup
up vote
0
down vote
favorite
I'm trying to find the src of a video tag with BeautifulSoup in python
import requests
from urllib.request import urlopen
from bs4 import BeautifulSoup as BS
url = '<some url>'
client_id = {'Client-ID': '<some id>'}
json_data = requests.get(url, headers=client_id).json()
def download(some_url) :
html_page = urlopen(some_url)
soup = BS(html_page, "html.parser")
link_to_vid = soup.find('video')['src']
print(link_to_vid)
# urllib.request.urlretrieve(video)
for x in range(0, num_clips):
resp_url = (json_data['data'][x]['url'])
print (resp_url)
download(resp_url)
When running this script I get an output of
*link from print(resp_url)*
Traceback (most recent call last):
File "script.py", line 28 in <module>
download(resp_url)
File "script.py", line 18 in download
link_to_vid = soup.find('video')['src']
TypeError: 'NoneType' object is not subscriptable
It seems to me that this error is occurring because BeautifulSoup cannot find a video tag on the webpage. I tried printing the whole html page I got from BeautifulSoup and it looks like it doesn't get the whole webpage, at least not what I can see from Chrome devtools.
Am I getting this error because the video is nested deep within divs? Why isn't BeautifulSoup getting the whole html page?
python html beautifulsoup
add a comment |
up vote
0
down vote
favorite
I'm trying to find the src of a video tag with BeautifulSoup in python
import requests
from urllib.request import urlopen
from bs4 import BeautifulSoup as BS
url = '<some url>'
client_id = {'Client-ID': '<some id>'}
json_data = requests.get(url, headers=client_id).json()
def download(some_url) :
html_page = urlopen(some_url)
soup = BS(html_page, "html.parser")
link_to_vid = soup.find('video')['src']
print(link_to_vid)
# urllib.request.urlretrieve(video)
for x in range(0, num_clips):
resp_url = (json_data['data'][x]['url'])
print (resp_url)
download(resp_url)
When running this script I get an output of
*link from print(resp_url)*
Traceback (most recent call last):
File "script.py", line 28 in <module>
download(resp_url)
File "script.py", line 18 in download
link_to_vid = soup.find('video')['src']
TypeError: 'NoneType' object is not subscriptable
It seems to me that this error is occurring because BeautifulSoup cannot find a video tag on the webpage. I tried printing the whole html page I got from BeautifulSoup and it looks like it doesn't get the whole webpage, at least not what I can see from Chrome devtools.
Am I getting this error because the video is nested deep within divs? Why isn't BeautifulSoup getting the whole html page?
python html beautifulsoup
it dynamic page, additional content added by javascript, use selenium.
– ewwink
Nov 22 at 9:05
1
As each URL usually requires different processing, the actual URL would be needed to help you.
– Martin Evans
Nov 22 at 12:21
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to find the src of a video tag with BeautifulSoup in python
import requests
from urllib.request import urlopen
from bs4 import BeautifulSoup as BS
url = '<some url>'
client_id = {'Client-ID': '<some id>'}
json_data = requests.get(url, headers=client_id).json()
def download(some_url) :
html_page = urlopen(some_url)
soup = BS(html_page, "html.parser")
link_to_vid = soup.find('video')['src']
print(link_to_vid)
# urllib.request.urlretrieve(video)
for x in range(0, num_clips):
resp_url = (json_data['data'][x]['url'])
print (resp_url)
download(resp_url)
When running this script I get an output of
*link from print(resp_url)*
Traceback (most recent call last):
File "script.py", line 28 in <module>
download(resp_url)
File "script.py", line 18 in download
link_to_vid = soup.find('video')['src']
TypeError: 'NoneType' object is not subscriptable
It seems to me that this error is occurring because BeautifulSoup cannot find a video tag on the webpage. I tried printing the whole html page I got from BeautifulSoup and it looks like it doesn't get the whole webpage, at least not what I can see from Chrome devtools.
Am I getting this error because the video is nested deep within divs? Why isn't BeautifulSoup getting the whole html page?
python html beautifulsoup
I'm trying to find the src of a video tag with BeautifulSoup in python
import requests
from urllib.request import urlopen
from bs4 import BeautifulSoup as BS
url = '<some url>'
client_id = {'Client-ID': '<some id>'}
json_data = requests.get(url, headers=client_id).json()
def download(some_url) :
html_page = urlopen(some_url)
soup = BS(html_page, "html.parser")
link_to_vid = soup.find('video')['src']
print(link_to_vid)
# urllib.request.urlretrieve(video)
for x in range(0, num_clips):
resp_url = (json_data['data'][x]['url'])
print (resp_url)
download(resp_url)
When running this script I get an output of
*link from print(resp_url)*
Traceback (most recent call last):
File "script.py", line 28 in <module>
download(resp_url)
File "script.py", line 18 in download
link_to_vid = soup.find('video')['src']
TypeError: 'NoneType' object is not subscriptable
It seems to me that this error is occurring because BeautifulSoup cannot find a video tag on the webpage. I tried printing the whole html page I got from BeautifulSoup and it looks like it doesn't get the whole webpage, at least not what I can see from Chrome devtools.
Am I getting this error because the video is nested deep within divs? Why isn't BeautifulSoup getting the whole html page?
python html beautifulsoup
python html beautifulsoup
asked Nov 22 at 9:01
BBaper
1
1
it dynamic page, additional content added by javascript, use selenium.
– ewwink
Nov 22 at 9:05
1
As each URL usually requires different processing, the actual URL would be needed to help you.
– Martin Evans
Nov 22 at 12:21
add a comment |
it dynamic page, additional content added by javascript, use selenium.
– ewwink
Nov 22 at 9:05
1
As each URL usually requires different processing, the actual URL would be needed to help you.
– Martin Evans
Nov 22 at 12:21
it dynamic page, additional content added by javascript, use selenium.
– ewwink
Nov 22 at 9:05
it dynamic page, additional content added by javascript, use selenium.
– ewwink
Nov 22 at 9:05
1
1
As each URL usually requires different processing, the actual URL would be needed to help you.
– Martin Evans
Nov 22 at 12:21
As each URL usually requires different processing, the actual URL would be needed to help you.
– Martin Evans
Nov 22 at 12:21
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427202%2ffinding-src-from-video-tag-in-a-div-in-beautifulsoup%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
it dynamic page, additional content added by javascript, use selenium.
– ewwink
Nov 22 at 9:05
1
As each URL usually requires different processing, the actual URL would be needed to help you.
– Martin Evans
Nov 22 at 12:21