utils.py 514 B

12345678910111213141516171819202122232425
  1. from driver.setup import setup_driver
  2. from utils.retry import retry_func
  3. from time import sleep
  4. import re
  5. from bs4 import BeautifulSoup
  6. def get_soup_driver(url):
  7. """
  8. Get the soup by driver
  9. """
  10. driver = setup_driver()
  11. retry_func(lambda: driver.get(url), name=url)
  12. sleep(1)
  13. source = re.sub(
  14. r"<!--.*?-->",
  15. "",
  16. driver.page_source,
  17. flags=re.DOTALL,
  18. )
  19. soup = BeautifulSoup(source, "html.parser")
  20. driver.close()
  21. driver.quit()
  22. return soup