Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
scraping video src fail
#4
Can do local test with html code you have posted.
local3.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8" />
  <title>Test site</title>
<head/>
<body>    
  <p id='foo'>hello world</p>
  <div id="container" >
  <div tableindex= -1>
   <video id="my_video_1_html5_api" class="vjs-tech" controlslist="nodownload" preload="auto" poster="https://vs02.520call.me/files/mp4/f/ttttt.jpg" <source src="https://vs02.520call.me/files/mp4/f/fwnOT.m3u8?t=1234444”  type="application/vnd.apple.mpegurl"></video>
</body>
</html>
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

#--| Setup
options = Options()
#options.add_argument("--headless")
browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe', options=options)
#--| Parse or automation
browser.get('file:///E:/div_code/scrape/local3.html')
p_tag = browser.find_elements_by_id('foo')
print(p_tag[0].text)

video_tag = browser.find_elements_by_xpath('//*[@id="my_video_1_html5_api"]')
print(video_tag)
Output:
hello world [<selenium.webdriver.remote.webelement.WebElement (session="1a81b871d83bdeb1e947cc8f1a074be6", element="cdf7afaf-c573-4f49-aee8-66bd8a4d3b40")>]
So it work the video tag will have no text have to use get_attribute to get info out.
>>> video_tag
[<selenium.webdriver.remote.webelement.WebElement (session="1a81b871d83bdeb1e947cc8f1a074be6", element="cdf7afaf-c573-4f49-aee8-66bd8a4d3b40")>]
>>> video_tag[0].text
''
>>> 
>>> video_tag[0].get_attribute('src')
'https://vs02.520call.me/files/mp4/f/fwnOT.m3u8?t=1234444%E2%80%9D%20%20type='
>>> video_tag[0].get_attribute('poster')
'https://vs02.520call.me/files/mp4/f/ttttt.jpg
Reply


Messages In This Thread
scraping video src fail - by jacklee26 - Jul-10-2021, 01:29 PM
RE: scraping video src fail - by snippsat - Jul-10-2021, 02:16 PM
RE: scraping video src fail - by jacklee26 - Jul-10-2021, 07:17 PM
RE: scraping video src fail - by snippsat - Jul-10-2021, 08:17 PM
RE: scraping video src fail - by jacklee26 - Jul-11-2021, 02:32 AM
RE: scraping video src fail - by snippsat - Jul-11-2021, 09:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why does [root.destroy, exit()]) fail after pyinstaller? Rpi Edward_ 4 766 Oct-18-2023, 11:09 PM
Last Post: Edward_
  How to calculated how many fail in each site(s) in csv files SamLiu 4 1,405 Sep-26-2022, 06:28 AM
Last Post: SamLiu
  Imports that work with Python 3.8 fail with 3.9 and 3.10 4slam 1 2,730 Mar-11-2022, 01:50 PM
Last Post: snippsat
  [SOLVED] Why does regex fail cleaning line? Winfried 5 2,645 Aug-22-2021, 06:59 PM
Last Post: Winfried
  fail to upgrade pygobject jiapei100 0 3,147 Aug-16-2018, 10:32 AM
Last Post: jiapei100
  Fail to allocate bitmap rsbeesh 7 16,071 Dec-13-2017, 01:36 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020