我們無法載入 Disqus。如果您是管理者請見我們的除錯指南。
照我文章裡面寫的,想取得"留言的回覆"(應該就是你說的二階留言)有兩種方法:
1. 在抓留言時 part 帶上 replies,取得的留言會有個 replies 欄位,裡面就包含此留言的回覆(注意:如果此留言沒有回覆就不會有此欄位),如下圖。但這種作法遇到"回覆"太多的好像會被截斷(我的印象啦)。
https://uploads.disquscdn.c...
2. 使用 Comments 資源,參考官方文件或以下圖片。
https://developers.google.c...
https://uploads.disquscdn.c...
你再試試看吧~
請問老師要如何將爬下來的資料存成json檔並輸出
你要先將整理好的資料由 Dict 格式轉成 JSON 格式,再儲存成 .json 檔案:
import json
# 抓取並整理後的資料
info = {
"id": "123456789",
"title": "影片標題",
"description": "影片描述",
"likeCount": 100,
"commentCount": 10,
"viewCount": 1000
}
# 轉成 JSON 格式的字串,並儲存至 .json 檔案
with open("sample.json", "w", encoding="utf-8") as file:
json.dump(info, file, ensure_ascii=False, indent=4)
`ensure_ascii=False` 不用轉成 ASCII,不然中文人眼會看不懂
想問老師要如何把爬下來的資料轉成excel csv檔
你需要把爬到的資料整理成 csv 套件支援的格式,再寫入檔案。
網路上有許多 Python 讀寫 csv 檔案的文章可以參考,例如:
https://blog.gtwang.org/programming/python-csv-file-reading-and-writing-tutorial/
如果你是使用 pandas 在操作資料,它本身就有 function 可以使用,像是:df.to_csv("output.csv")
Note: The statistics.dislikeCount property was made private as of December 13, 2021. This means that the property is included in an API response only if the API request was authenticated by the video owner. See the revision history for more information.
時間到了, dislikeCount就不能用了~
謝謝提醒~
這應該也是因應 YouTube 現在不能看到 Dislike 的數量了
請問一下,我翻閱了官方api文件,似乎沒有提到如何記錄現在的發燒影片,請問我該如何撰寫才可以記錄發燒影片排行
就是這個,謝謝老師
想請問一下
get_video(self, video_id, part='snippet,statistics')
的self應該填甚麼?video_id是=後面那一串。但我看了一下程式碼還是不太知道怎麼用這個函式,嗚嗚。
這是 Python 的語法
你可以搜尋 "Python類別(Class)" 文章來看
可能才會比較了解
問一下如何把評論放進Excel表格裏呢,我是新手優點不太會欸
已回覆你了哦~
成功拿取到影片的資料, 但有以下問題:
1. 影片的資料只會取得首50個, 50個以後的都不會顯示
2. 不會顯示「直播」類的影片
1. 這部分在"其他查詢參數"段落有提到,為了節省一次傳輸量,它會有一次最多筆數的上限,透過 pageToken 參數帶進上一次回傳資料中 nextPageToken 欄位的值,即可獲取下一頁。例如我之前寫的 爬蟲 Dcard API 2.0 版本?! 中 before 的參數也是類似的概念。
2. 直播影片我沒嘗試過,但它有另一個 Live Streaming API,你參考看看~
我帶入pagetoken的值之後,發現pagetoken沒有變化
抱歉,現在才看到
你是帶入上一個請求所回傳 nextPageToken 的值嗎?
還有你指沒有變化是說回傳的資料跟前一次的資料一模一樣嗎?
我正在学习使用Youtube DataAPI,试用了一个官方的例子:(https://developers.google.c...
# -*- coding: utf-8 -*-
# Sample Python code for youtube.videos.list
# See instructions for running these code samples locally:
# https://developers.google.c...
import os
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
scopes = ["https://www.googleapis.com/..."]
def main():
# Disable OAuthlib's HTTPS verification when running locally.
# *DO NOT* leave this option enabled in production.
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
api_service_name = "youtube"
api_version = "v3"
client_secrets_file = "YOUR_CLIENT_SECRET_FILE.json"
# Get credentials and create an API client
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file, scopes)
credentials = flow.run_console()
youtube = googleapiclient.discovery.b...(
api_service_name, api_version, credentials=credentials)
request = youtube.videos().list(
part="statistics",
id="Ks-_Mh1QhMc"
)
response = request.execute()
print(response)
if __name__ == "__main__":
main()
运行后输入authorization code后报错requests.exceptions.ProxyError: HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token (Caused by ProxyError('Cannot connect to proxy.', OSError(0, 'Error')))
怎么查询都没能得到解决方案,不知道可不可以打扰您询问一下这是什么原因?非常感谢您!!!
或者你可以試試 Google 的 Colab notebooks
https://colab.research.goog...
我在猜會不會是你那邊網路的問題,你連接 VPN 或斷開現有的 VPN 試試。
看起來是你那邊連不到 google api 驗證身分的網址。
https://stackoverflow.com/q...
如果可以解决,非常感谢您!
請問老師要如何爬取二階留言,知道要使用replies,但還是寫不出來