2019年8月16日金曜日

pythonとseleniumを使用して確実にページの先頭にスクロールする方法

調べればたくさん方法があると思いますが、何回試したがうまくいかなかったです。
最後辿り着くのが以下の通りでした。

driver = webdriver.Firefox()
driver.execute_script("window.scrollTo(0, 0);")

2019年8月13日火曜日

Centosでxzファイルの解凍方法

centosでxzファイルを解凍してみたら、以下のエラーが発生しました。

[root@18f0e71a757a ~]# tar xf gtk+-3.24.0.tar.xz
tar (child): xz: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
どうやら、パッケージが足りてないようで、xzツールをまずインストール

[root@18f0e71a757a ~]# yum install xz
再度「tar xf」コマンドをうったら無事にインストールできました。

ゾンビプロセスの消し方

ある日とあるプロセス消しても消えなかったので、よくみたらゾンビになっていた
以下の通りに、最後「defucnt」がついてる
[root@18f0e71a757a 528]# ps aux | grep 'firefox'
root       638  0.2  0.0      0     0 pts/0    Z    09:48   0:06 [firefox] <defunct>
root       936  0.8  0.0      0     0 pts/0    Z    10:21   0:07 [firefox] <defunct>
root      1087  1.1  0.0      0     0 pts/0    Z    10:24   0:08 [firefox] <defunct>
root      1234  0.9  0.0      0     0 pts/0    Z    10:24   0:07 [firefox] <defunct>
root      1372  0.7  0.0      0     0 pts/0    Z    10:25   0:05 [firefox] <defunct>
root      1511  0.8  0.0      0     0 pts/0    Z    10:26   0:06 [firefox] <defunct>
root      1668  1.0  0.0      0     0 pts/0    Z    10:28   0:06 [firefox] <defunct>
root      2041  0.0  0.0 103376  2028 pts/0    S+   10:37   0:00 grep firefox
どうにかして消したいので、調査したところ、親プロセスも一緒に消せば消えるらしい
早速、以下のコマンドで親プロセスも表示してみた

[root@18f0e71a757a 528]# ps -ef | grep defunct
root       638   622  0 09:47 pts/0    00:00:06 [firefox] <defunct>
root       936   920  0 10:21 pts/0    00:00:07 [firefox] <defunct>
root      1087  1071  0 10:24 pts/0    00:00:08 [firefox] <defunct>
root      1234  1218  0 10:24 pts/0    00:00:07 [firefox] <defunct>
root      1372  1356  0 10:25 pts/0    00:00:05 [firefox] <defunct>
root      1511  1495  0 10:26 pts/0    00:00:06 [firefox] <defunct>
root      1668  1652  0 10:28 pts/0    00:00:06 [firefox] <defunct>
root      2045    26  0 10:39 pts/0    00:00:00 grep defunct
親プロセスも一緒に消してみる
[root@18f0e71a757a 528]# kill -9 638 622
[root@18f0e71a757a 528]# ps -ef | grep defunct
root       936   920  0 10:21 pts/0    00:00:07 [firefox] <defunct>
root      1087  1071  0 10:24 pts/0    00:00:08 [firefox] <defunct>
root      1234  1218  0 10:24 pts/0    00:00:07 [firefox] <defunct>
root      1372  1356  0 10:25 pts/0    00:00:05 [firefox] <defunct>
root      1511  1495  0 10:26 pts/0    00:00:06 [firefox] <defunct>
root      1668  1652  0 10:28 pts/0    00:00:06 [firefox] <defunct>
root      2047    26  0 10:40 pts/0    00:00:00 grep defunct
見事に消すことができた

PS:ps -ef | grep defunctの説明

UID          PID     PPID       C    STIME      TTY          TIME              CMD
root       936   920  0 10:21 pts/0    00:00:07 [firefox] <defunct>
PIDは該当プロセスのID、PPIDは親プロセスのID