如何扫描网页并获取图像和 YouTube 嵌入?

发布于 2024-07-08 17:07:53 字数 202 浏览 6 评论 0原文

我正在构建一个网络应用程序,我需要获取给定 URL 上嵌入的所有图像和任何 Flash 视频(例如 youtube)。 我正在使用Python。

我已经用谷歌搜索过,但没有找到任何关于此的好信息(可能是因为我不知道这叫什么来搜索),有没有人有这方面的经验并且知道如何做到这一点?

我很想看到一些代码示例(如果有的话)。

谢谢!

I am building a web app where I need to get all the images and any flash videos that are embedded (e.g. youtube) on a given URL. I'm using Python.

I've googled, but have not found any good information about this (probably because I don't know what this is called to search for), does anyone have any experience with this and knows how it can be done?

I'd love to see some code examples if there are any available.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花落人断肠 2024-07-15 17:07:53

BeautifulSoup 是一个很棒的屏幕抓取库。 使用 urllib2 获取页面,并使用 BeautifulSoup 对其进行解析。 这是他们文档中的代码示例:

import urllib2
from BeautifulSoup import BeautifulSoup

page = urllib2.urlopen("http://www.icc-ccs.org/prc/piracyreport.php")
soup = BeautifulSoup(page)
for incident in soup('td', width="90%"):
    where, linebreak, what = incident.contents[:3]
    print where.strip()
    print what.strip()
    print

BeautifulSoup is a great screen-scraping library. Use urllib2 to fetch the page, and BeautifulSoup to parse it apart. Here's a code sample from their docs:

import urllib2
from BeautifulSoup import BeautifulSoup

page = urllib2.urlopen("http://www.icc-ccs.org/prc/piracyreport.php")
soup = BeautifulSoup(page)
for incident in soup('td', width="90%"):
    where, linebreak, what = incident.contents[:3]
    print where.strip()
    print what.strip()
    print
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文