0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

BeautifulSoupのfunction

Posted at

BeautifulSoupを用いた関数を作りました。最低限の間隔を置いて実行したく、下記のように書きましたが、もしよりよい方法があればご教示ください。m(_ _)m

from bs4 import BeautifulSoup
import requests
import time

time_start_stump_soup=0

def getSoup(url, timeSleep=3, check_each=0.2):
    global time_start_stump_soup
    while True:
        if time.time() - time_start_stump_soup > timeSleep:
            res = requests.session().get(url)
            soup = BeautifulSoup(res.content, 'lxml')
            time_start_stump_soup = time.time()
            return soup
        else:
            time.sleep(check_each)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?