使用BeautifulSoup解析网页中的链接很困难

2024-05-23 22:10:43 发布

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

我很难解析此网页中的所有链接:https://recordings.engineering.illinois.edu:8443/ess/portal/section/8a3458dc-ed31-4c93-8e3e-3b64b1f89fe8 我基本上想解析所有的链接,然后只保留你看到的视频文件链接下载每节课。你知道吗

导入httplib2 从bs4进口,SoupStrainer

http = httplib2.Http()
status, response =      http.request('https://recordings.engineering.illinois.edu:8443/ess/portal/section/8a3458dc-ed31-4c93-8e3e-3b64b1f89fe8')

for link in BeautifulSoup(response, "html.parser",parse_only      =SoupStrainer('a')):
    if link.has_attr('href'):
        print link['href']

上面是我应该解析链接的代码。你知道吗

然后我将使用webbrowser.open_new_tab(url)来打开每个链接上的新选项卡(这就是开始下载每个视频所需的全部内容)。你知道吗

看来beautifulsoup很难获得这个特定URL的链接。它可以很好地处理其他更简单的页面。对这个问题有什么看法吗?你知道吗


Tags: httpshttp链接responselinksectionportalhttplib2