简体   繁体   中英

Get pid of FirefoxBinary object with python/selenium/firefox

I am using python/selenium/firefox to scrape different websites. The scrapers are running as .cgi scripts on my server. Now I need to to get the pid of the currently running webdriver. Therefore I'm using this chunk of code

import psutil
driver = webdriver.Firefox(executable_path=pathToFF, firefox_binary=pathToBinaries, firefox_options=opts)
pid = driver.binary.process.pid

Unfortunately the following error occurs:

2018-05-31 08:05:59 'FirefoxBinary' object has no attribute 'process'
2018-05-31 08:05:59 line of error:557

So now my question is, how can I get the pid of my driver?

If I try with:

driver.service.process.pid

it works.

The only thing is that, in my tests, I'm receiving the # pid-1 . I mean, if (for example) the test return 50654 actually the pid is:

davide.patti$ ps -ex | grep firefox
50655 ??         0:03.45 /Applications/Firefox.app/Contents/MacOS/firefox-bin -marionette -profile /var/folders/b0/15xtry7n0157gq7m2j_n1srx2h0pkg/T/rust_mozprofile.rCHMaQdhIOyF

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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