所以,我们有一个网站,像pewdiepies YT主页,https://www.youtube.com/channel/UC-lHJZR3Gqxm24_Vd_AJ5Yw。我想写一个剧本,让我知道他的底数。我要用漂亮的汤吗?你知道吗
我知道,它保存在
yt格式字符串 id="subscriber-count" class="style-scope ytd-c4-tabbed-header-renderer">84,831,541 subscribers/yt-formatted-string>
我与网络开发无关,所以这对我来说是一堆胡言乱语。但一定有办法让我得到这个价值,没有靓汤,就一定有办法吗?你知道吗
import urllib.request
import json
import webbrowser
data = urllib.request.urlopen('https://www.youtube.com/channel/UC-lHJZR3Gqxm24_Vd_AJ5Yw')
print(data)
到目前为止我只有这些。你知道吗
从它看起来像你试图做的是得到一个指定通道的子计数。为此,我将使用googleyoutubeapi,因为它比web抓取更快、更可靠。下面是示例代码。你知道吗
1)获取API密钥并启用此库
2)获取Youtube频道的频道id,例如PewDiePie isUC-lHJZR3Gqxm24\u Vd\u AJ5Yw
3)使用指定的参数向下面的URL发出GET请求
3b)这将返回您需要解析的JSON响应
获取pewdiepies通道子计数的示例代码
你所做的是网页抓取。一个快速的谷歌搜索澄清了如何处理这个问题。你要找的代码
写作时的结果是:“84851474”
如果您想了解更多,可以深入研究web scraping in Python和XPath。你知道吗
相关问题 更多 >
编程相关推荐