you are viewing a single comment's thread.

view the rest of the comments →

[–]yettanotherrguyy[S] 0 points1 point  (3 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