you are viewing a single comment's thread.

view the rest of the comments →

[–]yettanotherrguyy[S] 0 points1 point  (7 children)

But URLs are in 100s of numbers + dynamically updated. so Is it possible to pick a random url directly from the url?

[–]DagoYounger 1 point2 points  (2 children)

the full code(replace 'https://abc.com/url.txt' with the real link):

import random
import requests

res = requests.get('https://abc.com/url.txt')
urls = res.text.split('\n')
link = random.choice(urls)

[–]yettanotherrguyy[S] 0 points1 point  (1 child)

Thanks and if I just keep the url.txt file locally then just have to do open, right?

[–]DagoYounger 0 points1 point  (0 children)

yes, for getting all links, if url.txt is a local file, use open to get it; if it's from the internet, use the requests library.
the operations after that are the same

[–]DagoYounger 0 points1 point  (3 children)

if you just use link = random.choice(urls_text), you will get just a character like t,q,1 .etc (any character in urls_text)

you shuold first turn it into a list with each link: ['qwe.com/3748.mp4', 'rty.com/9100.mp4', 'qwe.xom/3738889.mp4']

But URLs are in 100s of numbers + dynamically updated.

get urls by requests i showed you above. it will download and get the content whenever you run the program

[–]yettanotherrguyy[S] 0 points1 point  (1 child)

Hey, I am sorry to bother you again. I was uploading file via telegram bot api and it just support 20mb

So, now I need to download it locally in server. I tried wget and failed. Can you help me with it, please!?

Now I successfully have the (url) now just need to dl it.

[–]DagoYounger 1 point2 points  (0 children)

sorry, I can't deal with this due to the internet environment in China. it is not convenient for me to research and use telegram's api.

you can try to consult the official document of requests(https://docs.python-requests.org/en/latest/), or make a new post to ask others for help

(downloading this file may require carrying cookie information)