尝试使用beautifulsoup刮取iframe

2024-10-08 20:23:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我想抓取一段视频,但是beauthulsoup不会等iframe加载。我尝试过使用selenium,但是googlewebdriver会等待整个页面的加载,而且要花很长时间。在页面加载完成后,我也无法获取页面源。在

这是我的代码,我用beauthulsoup试过了,但什么也没得到

def get_vidCode_from_source(source_url):
    source_code = requests.get(source_url)
    plain_text = source_code.text
    soup = BeautifulSoup(plain_text,"html.parser")
    print(soup.find('iframe'))

get_vidCode_from_source('http://anilinkz.io/one-piece-episode-769?src=3')

所以尝试在iframe中获取视频链接:

enter image description here

除了硒之外,还有什么能得到iframes的好处呢?在


Tags: textfromurlsourceget视频seleniumcode
1条回答
网友
1楼 · 发布于 2024-10-08 20:23:29

我知道这有点旧,但是要使用selenium和获取页面源代码,请使用以下代码:

from selenium import webdriver
browser = webdriver.Chrome()
browser.get('http://anilinkz.io/one-piece-episode-769?src=3')
soup = BeautifulSoup(browser.page_source, "lxml")
browser.close()
for x in soup.find_all('iframe'):
    print(x)

相关问题 更多 >

    热门问题