Python set of selenium (mac version)

There was a time not used selenium modules, and also bought a new mac computer has no chance to use this module, cramming in front of linux-related operations, foggy feeling to learn.

Today want to write a new script, originally written snapped under the code perfect, so continue to take it to the selenium, blame js I learned a residue, had the feeling can also be used to break js.

Prime Minister installation selenium plug-in, download the plug-in with pip3 install older, I manually pycharm through which the plug-in with the new software a bit.

The Prime Minister said at the configuration on Chrome and the Chrome I should be through the official download the software, double-click to install. (By default, the environment variables should give you also installed chromedriver, location and then / usr / local / bin / chromedriver)

In fact, if you can start it, you do not have control, I can not, because they do not replace the chromedriver I start the software prompts low version. At that time I thought it was a low sleenium version, so it takes to upgrade it.

No way, download the new version of chromedriver

https://sites.google.com/a/chromium.org/chromedriver/ (need over the wall)

After the download, unzip, many online edition said I need these files moved to / usr / bin Now, I actually tried it, simply enough authority , enough for a root authority or, in fact, I read the book, (there are recommended on a custom file folder, and then by modifying .bash_profile add custom path to the environment variable, generally speaking, I think too much trouble, but if the can not use, I'm obsessive-compulsive disorder attack but also to modify the file back)

Just passed which found inside my computer has been added to the environment variable chromedriver / usr / local / bin /

Simple backup under sudo mv / usr / local / bin / chromedriver chromedriver.back

Then copy files over mv ~ / Downloads / chromedriver / usr / local / bin /

Then everything will be fine.

In fact, the environment variable is still very important piece of information, it is recommended equipment will bring more understanding of the understanding of the environment variable.

 

Since the beginning Chrom get it working, come to think firefox under emergency use, firefox I was relatively unfamiliar, previously been using search dogs browsers, firefox search dogs with a rogue.

firefox is quite simple:

Installation Geckodriver

Because of our automated script calls Firefox, so you need to call Geckodriver to drive the Firefox browser, the same as if the installation of Google Chrome also need chromedriver, Google browser and drive version has a correspondence table,

Official website address: https: //github.com/mozilla/geckodriver/releases

Download the corresponding version you feel

Finally, you need to move down after the decompression / usr / local / bin directory, so: mv geckodriver / usr / local / bin (in fact, I think does not matter, because this is my copy)

When not added to the environment variables can be added at initialization time:

 

from selenium.webdriver.firefox.options import Options

 

 

Options = Options () 
# options.headless = True

Driver = webdriver. Firefox ( executable_path = "./gdriver/geckodriver", Options = Options)

where you can fill executtable_path Road King, it is recommended to fill a relative path, so to be directly above the server can be used, (why I do not recommend to write the file environment variables, it is because you do not write it, this time to copy the installation package to go, where you can use)
there are options I did a test headless browser used .


Finally: firefox fact, there is still a lot of difference with Chorm set many, many fundamental issues Baidu rarely the answer, especially firefox, my English is very poor, even if google foreign data often do not understand.
Baidu is still relatively Chrom much information, and I can only still behind with Chrom.

I will also follow-up to commissioning and installation of the server, if not write very simple blog, a little bit complicated to write down, this thing with little older, I might forget tomorrow.

 

Guess you like

Origin www.cnblogs.com/sidianok/p/11773060.html