简体   繁体   English

带有Python的Selenium Webdriver /浏览器

[英]Selenium Webdriver/Browser with Python

I need to build a Python scraper to scrape data from a website where content is only displayed after a user clicks a link bound with a Javascript onclick function, and the page is not reloaded. 我需要构建一个Python抓取工具,以从网站上抓取数据,该网站仅在用户单击与Javascript onclick函数绑定的链接之后才显示内容,并且不会重新加载页面。 I've looked into Selenium in order to do this and played around with it a bit, and it seems Selenium opens a new Firefox web browser everytime I instantiate a driver: 为了做到这一点,我研究了Selenium并进行了一些尝试,似乎Selenium每次实例化驱动程序时都会打开一个新的Firefox Web浏览器:

 >>> driver = webdriver.Firefox()

Is this open browser required, or is there a way to get rid of it? 需要这种开放式浏览器,还是有办法摆脱它? I'm asking because the scraper is potentially part of a web app, and I'm afraid if multiple users start using it, I will have a bunch of browser windows open on my server. 我问是因为刮板可能是Web应用程序的一部分,而且如果多个用户开始使用它,恐怕我的服务器上会打开一堆浏览器窗口。

Yes, selenium automates web browsers. 是的,Selenium可以自动执行Web浏览器。 You can add this at the bottom of your python code to make sure the browser is closed at the end: 您可以在python代码的底部添加此代码,以确保浏览器最后关闭:

driver.quit()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM