- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
刚接触 beautiful soup 4,当我在 YouTube 上搜索某些内容时,我无法使用这个简单的代码来获取标签的内容。当我打印容器时,它只是将“[]”打印为我假设的空变量。有什么想法为什么这没有捡到任何东西吗?这是否与没有在 YouTube 上捕获正确的标签有关?在搜索 HTML 中,一个结果有以下标记:
<a id="video-title" class="yt-simple-endpoint style-scope ytd-video-renderer" aria-label="Kendrick Lamar - HUMBLE. by KendrickLamarVEVO 5 months ago 3 minutes, 4 seconds 322,571,817 views" href="https://www.youtube.com/watch?v=tvTRZJ-4EyI" title="Kendrick Lamar - HUMBLE.">
Kendrick Lamar - HUMBLE.
</a>
Python 代码:
import bs4
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
search = "damn"
my_url = "https://www.youtube.com/results?search_query=" + search
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
#html parsing
page_soup = soup(page_html, "html.parser")
containers = page_soup.find_all("a",{"id":"video-title"})
print(containers)
#result-count
最佳答案
在 YouTube 页面中动态加载结果,因此 id 和类名称将会更改。当您尝试解析页面时,请确保在 urllib 中而不是在浏览器中加载页面源时读取页面源代码查看它将解决您的问题的代码:
from bs4 import BeautifulSoup as bs
from urllib.request import *
page = urlopen('https://www.youtube.com/results?search_query=damn').read()
soup = bs(page,'html.parser')
results = soup.find_all('a',{'class':'yt-uix-sessionlink'})
for link in results:
print(l.get("href"))
代码将显示页面中的所有网址,因此您也应该解析它。
关于python - 为什么 find_all BeautifulSoup4 函数没有返回任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46376992/
我有一些使用 BeautifulSoup 的 Python 屏幕抓取代码,这让我很头疼。对 html 的一个小改动使我的代码中断,但我不明白为什么它无法工作。这基本上是 html 在解析时的外观演示:
我想找到页面上的所有链接,此代码仅获取以http://开头的链接,但大多数链接都是https:// 我如何编辑下面的代码来找到两者? for link in soup.find_all('a',att
我正在尝试解析一个具有多个同名类的网站。我想采用第一个(如网页上所示)类(class)的元素。但是,find_all 或 find 不保留解析的顺序。下面是我对 find_all 的实现 请帮忙: i
您好,我正在尝试从网站获取一些信息。请原谅我,如果我的格式有任何错误,这是我第一次发布到 SO。 soup.find('div', {"class":"stars"}) 从这里我收到 我需要 “
我希望使用 BeautifulSoup 来解析一些 HMTL。我有一个有几行的表。我正在尝试查找满足某些条件(某些属性值)的行,并稍后在我的代码中使用该行的索引。 问题是:是否find_all()在它
假设我有这个 html 代码: html = """ Text 1 Text 2 """ 使用此代码: from bs4 import BeautifulSoup as bs soup = bs
我想提取 this 中的所有网址网页。 我使用的python代码是这个 htmlfile=urllib.urlopen("http://dubai.dubizzle.com/property-for-
当我抓取一个网页时,我总是遇到一个问题。 AttributeError: ResultSet object has no attribute 'find'. You're probably treat
我在 BeautifulSoup 中发现了一些奇怪的行为,如下面的示例所示。 import re from bs4 import BeautifulSoup html = """This has a
这是我第一次使用 BeautifulSoup,我不知道我做错了什么 Picks Bans Combined 这是我正在使用的 HTM
我有以下 xml, https://mystore.com/products-t-shirt.xml 2019-04-11T00:01:42-04:00 daily
我正在尝试抓取this page所有优惠,并想要迭代 但是page_soup.find_all("p", "white-strip")返回一个空列表 []。 到目前为止我的代码- from urlli
我正在做一些抓取并遇到了问题。 现在我的代码如下所示: pn = soup.find_all("a", {"class": "full"}) pfp = soup.find_all("td", {"c
我正在尝试查找具有 column 类的所有 p 标签。 This is a column More columns heh 我试过: soup.find_all(class_='column') 它返
我是 Python 的新手。我最近的项目是从博彩网站上抓取数据。我要抓取的是网页中的赔率信息。 这是我的代码 from urllib.request import urlopen as uReq fr
我正在使用 beautifulsoup 和 html 解析器执行抓取,并选择了我想要使用的 html 部分并将其保存为“容器”。 from urllib.request import urlopen
主要问题 我知道如何使用 find_all() 检索具有特定值属性的元素,但我找不到任何示例来说明如何检索具有多个可接受值之一的属性的元素。在我的例子中,我正在使用 DITA XML,我想检索范围属性
如何将 bs4 与带有空格的类标签的 find_all 一起使用? container = containers[0] product_container = container.find_all('
我目前正在研究网络爬虫。我希望我的代码从我抓取的所有网址中获取文本。函数 getLinks() 找到我想从中获取数据的链接并将它们放入数组中。该数组目前充满了 12 个链接,如下所示:' http:/
这个问题在这里已经有了答案: python3 print unicode to windows xp console encode cp437 (2 个答案) 关闭 7 年前。 我从 tutoria
我是一名优秀的程序员,十分优秀!