Skip to content

Commit e442c25

Browse files
committed
add ytb comment
1 parent b9d4a0d commit e442c25

9 files changed

Lines changed: 23167 additions & 6 deletions

File tree

Pipfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
8+
[packages]
9+
requests = {extras = ["socks"],version = "*"}
10+
11+
[requires]
12+
python_version = "3.7"

Pipfile.lock

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blog/crawler_blog_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
headers = {
1717
'Connection': 'Keep-Alive',
18-
'Accept': 'text/html, application/xhtml+xml, */*',
18+
'Accept': 'text.txt/html, application/xhtml+xml, */*',
1919
'Accept-Language': 'en-US,en;q=0.8,zh-Hans-CN;q=0.5,zh-Hans;q=0.3',
2020
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Sa",
2121
"Referer": "http://www.jobbole.com/",

heart2/heart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def fetch_data(uid=None, container_id=None):
5252
for card in cards:
5353
# 每条微博的正文内容
5454
if card.get("card_type") == 9:
55-
text = card.get("mblog").get("text")
55+
text = card.get("mblog").get("text.txt")
5656
text = clean_html(text)
5757
blogs.append(text)
5858
page += 1

juejin/juejin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
headers = {
1717
'Connection': 'Keep-Alive',
18-
'Accept': 'text/html, application/xhtml+xml, */*',
18+
'Accept': 'text.txt/html, application/xhtml+xml, */*',
1919
'Accept-Language': 'en-US,en;q=0.8,zh-Hans-CN;q=0.5,zh-Hans;q=0.3',
2020
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
2121
"HOST": "api.leancloud.cn",

juejin/test.py

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

xingqiu/xingqiu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def str_to_dict(s, join_symbol="\n", split_symbol=":"):
3333

3434
# 直接从浏览器里面拷贝过来的,请替换成你自己的浏览器中的内容
3535
headers = """
36-
Accept: application/json, text/plain, */*
36+
Accept: application/json, text.txt/plain, */*
3737
Accept-Encoding: gzip, deflate, br
3838
Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7
3939
Authorization: 8EAE71AC-081C-FE82-BE8C-954696
@@ -56,7 +56,7 @@ def crawl(url):
5656
if len(topics) <= 1:
5757
return
5858
for i in topics:
59-
print(i.get("talk").get("text")[:10])
59+
print(i.get("talk").get("text.txt")[:10])
6060
db.topics.insert_one(i)
6161
else:
6262
last_time = i.get("create_time")

youbute_comment/__init__.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""
2+
获取youtube视频下的评论
3+
4+
思路:
5+
6+
基于youtube官方的API来获取, 这里是关于如何初始化配置的文档https://developers.google.com/youtube/v3/getting-started
7+
8+
接口文档:https://developers.google.com/youtube/v3/docs/channelSections/list
9+
10+
视频地址:https://www.youtube.com/watch?v=FWMIPukvdsQ
11+
12+
"""
13+
import requests
14+
15+
# 在 API Console 配置生成
16+
key = "xxxxxx"
17+
# 视频ID
18+
videoId = "FWMIPukvdsQ"
19+
20+
url = f"https://www.googleapis.com/youtube/v3/commentThreads?" \
21+
f"key={key}&" \
22+
f"textFormat=plainText&" \
23+
f"part=snippet&" \
24+
f"videoId={videoId}&" \
25+
f"maxResults=100"
26+
27+
proxies = {
28+
'http': 'socks5://127.0.0.1:1080',
29+
'https': 'socks5://127.0.0.1:1080',
30+
}
31+
32+
33+
# 获取一下页的凭证
34+
35+
36+
def main():
37+
nextPageToken = "QURTSl9pMkR0YkxlcE1iOHhlLU1lNi1XWGhzTHdpUmlCN2w1UmJDNlVBaEhnT1dyejVFb3dnVGdWbExRSFNtMVRrNjE1TWVPWC04UVN2VGJrMkhjZ01KVmJpNllrRlVkdUFRWk1yVHp2cW1ZbjVNcXpFc2ZzRlI3ZkRlM3ZPUm1CalZSX1NkaE9qcEY4Tl8yUWRyMmN3"
38+
while nextPageToken is not None:
39+
if nextPageToken:
40+
params = {"pageToken": nextPageToken}
41+
else:
42+
params = None
43+
res = requests.get(url, proxies=proxies, params=params)
44+
data = res.json()
45+
import pprint
46+
nextPageToken = data.get("nextPageToken")
47+
print(nextPageToken)
48+
items = data.get("items")
49+
for item in items:
50+
comment = item.get("snippet").get("topLevelComment").get("snippet").get("textDisplay")
51+
print(comment)
52+
import time
53+
time.sleep(1)
54+
print("==================")
55+
56+
57+
58+
59+
if __name__ == '__main__':
60+
main()

0 commit comments

Comments
 (0)