def __crawl_user(self, uid):
if uid.isdigit():
uid = self.__switch_id(uid)
payload = {"operationName": "privateFeedsQuery",
"variables": {"principalId": uid, "pcursor": "", "count": 999},
"query": "query privateFeedsQuery($principalId: String, $pcursor: String, $count: Int) {\n privateFeeds(principalId: $principalId, pcursor: $pcursor, count: $count) {\n pcursor\n list {\n id\n thumbnailUrl\n poster\n workType\n type\n useVideoPlayer\n imgUrls\n imgSizes\n magicFace\n musicName\n caption\n location\n liked\n onlyFollowerCanComment\n relativeHeight\n timestamp\n width\n height\n counts {\n displayView\n displayLike\n displayComment\n __typename\n }\n user {\n id\n eid\n name\n avatar\n __typename\n }\n expTag\n __typename\n }\n __typename\n }\n}\n"}
res = requests.post(self.__data_url, headers=self.__headers, json=payload)
works = json.loads(res.content.decode(encoding='utf-8', errors='strict'))['data']['privateFeeds']['list']
if not os.path.exists("../data"):
os.makedirs("../data")
# 這兩行代碼將response寫入json供分析
# with open("data/" + uid + ".json", "w") as fp:
# fp.write(json.dumps(works, indent=2))
# 防止該用戶在直播,第一個作品默認為直播,導致獲取信息為NoneType
if works[0]['id'] is None:
works.pop(0)
name = re.sub(r'[\\/:*?"<>|\r\n]+', "", works[0]['user']['name'])
dir = "data/" + name + "(" + uid + ")/"
# print(len(works))
if not os.path.exists(dir):
os.makedirs(dir)
# if not os.path.exists(dir + ".list"):
# print("")
print("開始爬取用戶 " + name + ",保存在目錄 " + dir)
print(" 共有" + str(len(works)) + "個作品")
for j in range(len(works)):
self.__crawl_work(uid, dir, works[j], j + 1)
time.sleep(1)
print("用戶 " + name + "爬取完成!")
print()
time.sleep(1)
快手分為五種類型的作品,在作品里面表現為workType屬性
def __crawl_work(self, uid, dir, work, wdx):
w_type = work['workType']
w_caption = re.sub(r"\s+", " ", work['caption'])
w_name = re.sub(r'[\/:*?"<>|\r\n]+', "", w_caption)[0:24]
w_time = time.strftime('%Y-%m-%d', time.localtime(work['timestamp'] / 1000))
if w_type == 'vertical' or w_type == 'multiple' or w_type == "single" or w_type == 'ksong':
w_urls = work['imgUrls']
l = len(w_urls)
print(" " + str(wdx) + ")圖集作品:" + w_caption + "," + "共有" + str(l) + "張圖片")
for i in range(l):
p_name = w_time + "_" + w_name + "_" + str(i + 1) + ".jpg"
pic = dir + p_name
if not os.path.exists(pic):
r = requests.get(w_urls[i])
r.raise_for_status()
with open(pic, "wb") as f:
f.write(r.content)
print(" " + str(i + 1) + "/" + str(l) + " 圖片 " + p_name + " 下載成功 √")
else:
print(" " + str(i + 1) + "/" + str(l) + " 圖片 " + p_name + " 已存在 √")
elif w_type == 'video':
w_url = self.__work_url + work['id']
res = requests.get(w_url, headers=self.__headers_mobile,
params={"fid": 1841409882, "cc": "share_copylink", "shareId": "143108986354"})
html = res.text
waitreplace = work['id'] + '".*?"srcNoMark":"(.*?)"'
v_url = re.findall(waitreplace, html)
# pattern = re.compile(r"playUrl", re.MULTILINE | re.DOTALL)
# script = soup.find("script", text=pattern)
# s = pattern.search(script.text).string
# v_url = s.split('playUrl":"')[1].split('.mp4')[0].encode('utf-8').decode('unicode-escape') + '.mp4'
try:
print(" " + str(wdx) + ")視頻作品:" + w_caption)
except:
print(" 這里似乎有點小錯誤,已跳過")
v_name = w_time + "_" + w_name + ".mp4"
video = dir + v_name
if v_url:
if not os.path.exists(video):
r = requests.get(v_url[0])
r.raise_for_status()
with open(video, "wb") as f:
f.write(r.content)
print(" 視頻 " + v_name + " 下載成功 √")
else:
print(" 視頻 " + v_name + " 已存在 √")
else:
print("未找到視頻")
else:
print("錯誤的類型")
注意事項:
項目源碼地址 https://github.com/oGsLP/kuaishou-crawler
網頁中常見的多媒體文件包括音頻文件和視頻文件,對于在線音頻和視頻,我們往往都是使用embed標簽來插入。embed語法:
1 <embed src="”視頻地址”" type="”audio/x-pn-realaudio-plugin”"
2 console="”Clip1〃" controls="”ControlPanel,StatusBar”" height="”330〃"
3 width="”450〃" autostart="”true”" title="undefined">
<embed src="要播放的文件網址" ;="" autostart="true" loop="true" width="400"
height="350">
html中網頁中如何插入音頻和視頻?
舉例1:插入音頻文件
1 <title>插入音頻文件</title>
2
3
4 <embed src="media/西班牙舞曲.mp3" width="400px" height="80px">
在瀏覽器預覽效果如下:
說明:
我們可以看到,使用embed標簽插入音頻文件還會有一個播放界面,界面上有幾個簡單的功能按鈕。
舉例2:插入視頻文件
1 <title>插入音頻文件</title>
2
3
4 <embed src="media/小蘋果.wmv" width="400px" height="80px">
在瀏覽器預覽效果如下:
注意:
由于音頻和視頻文件比較大,所以在這里我們就不提供大家在線測試的功能。不過大家可以在自己計算機上面測試一下代碼。
使用embed標簽插入視頻,在瀏覽器我們也可以看到,瀏覽器提供了一個簡單的操作界面。embed標簽支持的視頻格式很多,大部分主流格式都支持。
embed標簽能支持大部分格式的視頻文件,反正主流的如.mp4、.avi、.rmvb等都支持。如果你使用embed標簽不能播放視頻,那就可能是你視頻格式有問題或者編碼有問題。你可以用格式工廠轉換一下格式。
以上就是html中網頁中如何插入音頻和視頻?
在WebRTC中有一個api 可以用來獲取桌面:getDisplayMedia
var promise = navigator.mediaDevices.getDisplayMedia(constraints);
constraints可選 constraints中約束與getUserMedia函數中的一致。
采集平面數據:這個功能在chrome中是實驗性的項目,所以只有對最新的項目開放。
在實戰之前我們要打開瀏覽器,做一下設置 chrome://flags/#enable-experimental-web-platform-features
如下圖所示:
接下來我們看看具體的js代碼如下:
C++音視頻開發學習資料:點擊領取→音視頻開發(資料文檔+視頻教程+面試題)(FFmpeg+WebRTC+RTMP+RTSP+HLS+RTP)
*請認真填寫需求信息,我們會在24小時內與您取得聯系。