0

I am using selenium to run a web scraping service. E.g.

class Scraper:
  def __init__(self):
    self.driver = webdriver.Chrome('drivers/chromedriver')
  def __del__(self):
    self.driver.close()

My superficial understanding of networking is that when we spin up a webdriver, we open a local TCP port that makes http requests to load webpages. I am also under the assumption that when we call self.driver.close, we can close that connection and free up our ports.

However, after working with this I've seen a ton of chromedriver instances still open on my computer. I ran sudo lsof -i -n -P | grep TCP. What is going on? Is my understanding wrong?

If a program that opens this webdriver terminates, and I did not specify __del__, will it be guaranteed to leave my connection open? If I do specify __del__ then will python handle closing the port?

Jason Kang
  • 94
  • 7
  • use `self.driver.quit()` instead of `close()`. check here https://stackoverflow.com/questions/15067107/difference-between-webdriver-dispose-close-and-quit – cjlee Dec 29 '21 at 06:50
  • I see - so is my understanding of selenium / TCP correct? – Jason Kang Dec 29 '21 at 06:53

0 Answers0