Last active
March 26, 2020 21:56
-
-
Save arvchristos/02091fae3b9048f41dc8caedf3f4ef8c to your computer and use it in GitHub Desktop.
Get all youtube links of a Discourse topic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
import json | |
with urllib.request.urlopen("https://linux-user.gr/t/125.json") as url: | |
data = json.loads(url.read().decode()) | |
# construct the biggest query of the world | |
start_url = "https://linux-user.gr/t/125/posts.json?" | |
for stream_id in data['post_stream']['stream']: | |
start_url = start_url + "post_ids[]=" + str(stream_id) + "&" | |
with urllib.request.urlopen(start_url) as posts_url: | |
post_data = json.loads(posts_url.read().decode()) | |
for post in post_data['post_stream']['posts']: | |
try: | |
for link in post['link_counts']: | |
if link['title'] == 'YouTube': | |
print(link['url']) | |
except KeyError as e: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment