Skip to content

Instantly share code, notes, and snippets.

View aftandilmmd's full-sized avatar
🏠
Working from home

Aftandil MMD aftandilmmd

🏠
Working from home
View GitHub Profile
@kboghe
kboghe / forcatchloop.py
Last active October 6, 2022 17:33
for-catch loop
import requests
from bs4 import BeautifulSoup
import random
headers_browser = {'Connection': 'close',"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"Accept-Encoding": "gzip","Accept-Language": "en-US,en;q=0.9,es;q=0.8", "Upgrade-Insecure-Requests": "1","User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"}
for i in range(3): # loop the try-part (i.e. opening the link) until it works, but only try it 4 times at most#
try: #try the following:#
random_sleep_link = random.uniform(10, 15) #sleep for a random chosen amount of seconds between 10 and 15 seconds#