How to get specific data using BeautifulSoup


How to get specific data using BeautifulSoup



I'm not sure how to get a specific result from this:


<div class="videoPlayer">
<div class="border-radius-player">
<div id="allplayers" style="position:relative;width:100%;height:100%;overflow: hidden;">
<div id="box">
<div id="player_content" class="todo" style="text-align: center; display: block;">
<div id="player" class="jwplayer jew-reset jew-skin-seven jw-state-paused jw-flag-user-inactive" tabindex="0">
<div class="jw-media jw-reset">
<video class="jw-video jw-reset" x-webkit-playsinline="" src="https:EXAMPLE-URL-HERE" preload="metadata"></video>
</div">



How would I get the src in <video class="jw-video jw-reset" x-webkit-playsinline="" src="https:EXAMPLE-URL-HERE" preload="metadata"></video>


src


<video class="jw-video jw-reset" x-webkit-playsinline="" src="https:EXAMPLE-URL-HERE" preload="metadata"></video>



This is what I've tried so far:


import urllib.request
from bs4 import BeautifulSoup

url = "https://someurlhere"

a = urllib.request.Request(url, headers={'User-Agent' : "Cliqz"})
b = urllib.request.urlopen(a) # prevent "Permission denies"

soup = BeautifulSoup(b, 'html.parser')

for video_class in soup.select("div.videoPlayer"):
print(video_class.text)



Which returns parts of it but not down to video class


video class





Requests only download a static webpage and are unable to deal with javascript code. Can you do a simple string search in b to make sure that the elements you need exists in the html code?
– Simas Joneliunas
Jul 2 at 0:40





It doesn't, it goes down to box but I thought that BeautifulSoup would be able to handle that.
– HelloThereToad
Jul 2 at 0:47


box





Try for video_class in soup.select("div.videoPlayer video.jw-video.jw-reset"): print(video_class.attrs['src'])
– The fourth bird
Jul 2 at 7:34


for video_class in soup.select("div.videoPlayer video.jw-video.jw-reset"): print(video_class.attrs['src'])




1 Answer
1



Requests is a simple html client, it cannot execute javascripts.



You have three more options to try here though!






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to add background colour in existing image using Swift?

Moria Casán

How to make file upload 'Required' in Contact Form 7?