Julie  Donnelly

Julie Donnelly

1594203060

PostgreSQL ODBC driver on Windows 7 x64

They asked us to write a database cursor. The topic is simple, but you need to use all sorts of database features, such as domains, UDF, triggers, stored procedures, etc. etc. As a programming language, C ++ was chosen with the wonderful Qt library.

As a DBMS, I wanted to use my favorite, until recently, MySQL, but in view of the lack of domain support in it, my choice fell on PostgreSQL (sooner or later I will transfer everything to PostgreSQL).

I was too lazy to recompile Qt, and since odbc support was initially included, I decided to use the PostgreSQL ODBC Driver. You can download it here . I put it, I just put it, only in odbcad32.exe it never appeared. I thought that the matter was in my Windows 7 x64, as it turned out later the whole thing was in **x64. **And then Google began. There were two ways to solve this problem.

Method number 1

I found a resource where it is fashionable to download a recompiled driver for 64-bit architecture . It is installed without problems, everything appears in the list of drivers. I created a DSN with the necessary settings, but when I tried to open a connection, my Qt-based application cursed that the ODBC driver architecture does not match the application architecture (I have 32-bit Qt). So this method did not suit me. And I had to look for another way.

Method number 2

Put the original ODBC driver . And then we correct the registry. Create the pgodbc.reg file with the following contents:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINESOFTWAREODBCODBCINST.INIPostgreSQL Unicode]
"APILevel"="1"
"ConnectFunctions"="YYN"
"Driver"="C:\postgresodbcdlls\psqlodbc35w.dll"
"DriverODBCVer"="03.51"
"FileUsage"="0"
"Setup"="C:\postgresodbcdlls\psqlodbc35w.dll"
"SQLLevel"="1"
"UsageCount"=dword:00000001

[HKEY_LOCAL_MACHINESOFTWAREODBCODBCINST.INIODBC Drivers]
"PostgreSQL Unicode"="Installed"

The path to psqlodbc35w.dll is changed to your own.

Now the original driver is also visible in odbcad32.exe

#odbc #postgresql #windows 7

What is GEEK

Buddha Community

PostgreSQL ODBC driver on Windows 7 x64

Jordan Sanders

1623423999

Nice article!
ODBC is hugely popular among application developers as it allows to write a single application to access data in relational and non-relational data sources from different vendors.

Julie  Donnelly

Julie Donnelly

1594203060

PostgreSQL ODBC driver on Windows 7 x64

They asked us to write a database cursor. The topic is simple, but you need to use all sorts of database features, such as domains, UDF, triggers, stored procedures, etc. etc. As a programming language, C ++ was chosen with the wonderful Qt library.

As a DBMS, I wanted to use my favorite, until recently, MySQL, but in view of the lack of domain support in it, my choice fell on PostgreSQL (sooner or later I will transfer everything to PostgreSQL).

I was too lazy to recompile Qt, and since odbc support was initially included, I decided to use the PostgreSQL ODBC Driver. You can download it here . I put it, I just put it, only in odbcad32.exe it never appeared. I thought that the matter was in my Windows 7 x64, as it turned out later the whole thing was in **x64. **And then Google began. There were two ways to solve this problem.

Method number 1

I found a resource where it is fashionable to download a recompiled driver for 64-bit architecture . It is installed without problems, everything appears in the list of drivers. I created a DSN with the necessary settings, but when I tried to open a connection, my Qt-based application cursed that the ODBC driver architecture does not match the application architecture (I have 32-bit Qt). So this method did not suit me. And I had to look for another way.

Method number 2

Put the original ODBC driver . And then we correct the registry. Create the pgodbc.reg file with the following contents:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINESOFTWAREODBCODBCINST.INIPostgreSQL Unicode]
"APILevel"="1"
"ConnectFunctions"="YYN"
"Driver"="C:\postgresodbcdlls\psqlodbc35w.dll"
"DriverODBCVer"="03.51"
"FileUsage"="0"
"Setup"="C:\postgresodbcdlls\psqlodbc35w.dll"
"SQLLevel"="1"
"UsageCount"=dword:00000001

[HKEY_LOCAL_MACHINESOFTWAREODBCODBCINST.INIODBC Drivers]
"PostgreSQL Unicode"="Installed"

The path to psqlodbc35w.dll is changed to your own.

Now the original driver is also visible in odbcad32.exe

#odbc #postgresql #windows 7

ERIC  MACUS

ERIC MACUS

1647540000

Substrate Knowledge Map For Hackathon Participants

Substrate Knowledge Map for Hackathon Participants

The Substrate Knowledge Map provides information that you—as a Substrate hackathon participant—need to know to develop a non-trivial application for your hackathon submission.

The map covers 6 main sections:

  1. Introduction
  2. Basics
  3. Preliminaries
  4. Runtime Development
  5. Polkadot JS API
  6. Smart Contracts

Each section contains basic information on each topic, with links to additional documentation for you to dig deeper. Within each section, you'll find a mix of quizzes and labs to test your knowledge as your progress through the map. The goal of the labs and quizzes is to help you consolidate what you've learned and put it to practice with some hands-on activities.

Introduction

One question we often get is why learn the Substrate framework when we can write smart contracts to build decentralized applications?

The short answer is that using the Substrate framework and writing smart contracts are two different approaches.

Smart contract development

Traditional smart contract platforms allow users to publish additional logic on top of some core blockchain logic. Since smart contract logic can be published by anyone, including malicious actors and inexperienced developers, there are a number of intentional safeguards and restrictions built around these public smart contract platforms. For example:

Fees: Smart contract developers must ensure that contract users are charged for the computation and storage they impose on the computers running their contract. With fees, block creators are protected from abuse of the network.

Sandboxed: A contract is not able to modify core blockchain storage or storage items of other contracts directly. Its power is limited to only modifying its own state, and the ability to make outside calls to other contracts or runtime functions.

Reversion: Contracts can be prone to undesirable situations that lead to logical errors when wanting to revert or upgrade them. Developers need to learn additional patterns such as splitting their contract's logic and data to ensure seamless upgrades.

These safeguards and restrictions make running smart contracts slower and more costly. However, it's important to consider the different developer audiences for contract development versus Substrate runtime development.

Building decentralized applications with smart contracts allows your community to extend and develop on top of your runtime logic without worrying about proposals, runtime upgrades, and so on. You can also use smart contracts as a testing ground for future runtime changes, but done in an isolated way that protects your network from any errors the changes might introduce.

In summary, smart contract development:

  • Is inherently safer to the network.
  • Provides economic incentives and transaction fee mechanisms that can't be directly controlled by the smart contract author.
  • Provides computational overhead to support graceful logical failures.
  • Has a low barrier to entry for developers and enables a faster pace of community interaction.

Substrate runtime development

Unlike traditional smart contract development, Substrate runtime development offers none of the network protections or safeguards. Instead, as a runtime developer, you have total control over how the blockchain behaves. However, this level of control also means that there is a higher barrier to entry.

Substrate is a framework for building blockchains, which almost makes comparing it to smart contract development like comparing apples and oranges. With the Substrate framework, developers can build smart contracts but that is only a fraction of using Substrate to its full potential.

With Substrate, you have full control over the underlying logic that your network's nodes will run. You also have full access for modifying and controlling each and every storage item across your runtime modules. As you progress through this map, you'll discover concepts and techniques that will help you to unlock the potential of the Substrate framework, giving you the freedom to build the blockchain that best suits the needs of your application.

You'll also discover how you can upgrade the Substrate runtime with a single transaction instead of having to organize a community hard-fork. Upgradeability is one of the primary design features of the Substrate framework.

In summary, runtime development:

  • Provides low level access to your entire blockchain.
  • Removes the overhead of built-in safety for performance.
  • Has a higher barrier of entry for developers.
  • Provides flexibility to customize full-stack application logic.

To learn more about using smart contracts within Substrate, refer to the Smart Contract - Overview page as well as the Polkadot Builders Guide.

Navigating the documentation

If you need any community support, please join the following channels based on the area where you need help:

Alternatively, also look for support on Stackoverflow where questions are tagged with "substrate" or on the Parity Subport repo.

Use the following links to explore the sites and resources available on each:

Substrate Developer Hub has the most comprehensive all-round coverage about Substrate, from a "big picture" explanation of architecture to specific technical concepts. The site also provides tutorials to guide you as your learn the Substrate framework and the API reference documentation. You should check this site first if you want to look up information about Substrate runtime development. The site consists of:

Knowledge Base: Explaining the foundational concepts of building blockchain runtimes using Substrate.

Tutorials: Hand-on tutorials for developers to follow. The first SIX tutorials show the fundamentals in Substrate and are recommended for every Substrate learner to go through.

How-to Guides: These resources are like the O'Reilly cookbook series written in a task-oriented way for readers to get the job done. Some examples of the topics overed include:

  • Setting up proper weight functions for extrinsic calls.
  • Using off-chain workers to fetch HTTP requests.
  • Writing tests for your pallets It can also be read from

API docs: Substrate API reference documentation.

Substrate Node Template provides a light weight, minimal Substrate blockchain node that you can set up as a local development environment.

Substrate Front-end template provides a front-end interface built with React using Polkadot-JS API to connect to any Substrate node. Developers are encouraged to start new Substrate projects based on these templates.

If you face any technical difficulties and need support, feel free to join the Substrate Technical matrix channel and ask your questions there.

Additional resources

Polkadot Wiki documents the specific behavior and mechanisms of the Polkadot network. The Polkadot network allows multiple blockchains to connect and pass messages to each other. On the wiki, you can learn about how Polkadot—built using Substrate—is customized to support inter-blockchain message passing.

Polkadot JS API doc: documents how to use the Polkadot-JS API. This JavaScript-based API allows developers to build custom front-ends for their blockchains and applications. Polkadot JS API provides a way to connect to Substrate-based blockchains to query runtime metadata and send transactions.

Quiz #1

👉 Submit your answers to Quiz #1

Basics

Set up your local development environment

Here you will set up your local machine to install the Rust compiler—ensuring that you have both stable and nightly versions installed. Both stable and nightly versions are required because currently a Substrate runtime is compiled to a native binary using the stable Rust compiler, then compiled to a WebAssembly (WASM) binary, which only the nightly Rust compiler can do.

Also refer to:

Lab #1

👉 Complete Lab #1: Run a Substrate node

Interact with a Substrate network using Polkadot-JS apps

Polkadot JS Apps is the canonical front-end to interact with any Substrate-based chain.

You can configure whichever endpoint you want it to connected to, even to your localhost running node. Refer to the following two diagrams.

  1. Click on the top left side showing your currently connected network:

assets/01-polkadot-app-endpoint.png

  1. Scroll to the bottom of the menu, open DEVELOPMENT, and choose either Local Node or Custom to specify your own endpoint.

assets/02-polkadot-app-select-endpoint.png

Quiz #2

👉 Complete Quiz #2

Lab #2

👉 Complete Lab #2: Using Polkadot-JS Apps

Notes: If you are connecting Apps to a custom chain (or your locally-running node), you may need to specify your chain's custom data types in JSON under Settings > Developer.

Polkadot-JS Apps only receives a series of bytes from the blockchain. It is up to the developer to tell it how to decode and interpret these custom data type. To learn more on this, refer to:

You will also need to create an account. To do so, follow these steps on account generation. You'll learn that you can also use the Polkadot-JS Browser Plugin (a Metamask-like browser extension to manage your Substrate accounts) and it will automatically be imported into Polkadot-JS Apps.

Notes: When you run a Substrate chain in development mode (with the --dev flag), well-known accounts (Alice, Bob, Charlie, etc.) are always created for you.

Lab #3

👉 Complete Lab #3: Create an Account

Preliminaries

You need to know some Rust programming concepts and have a good understanding on how blockchain technology works in order to make the most of developing with Substrate. The following resources will help you brush up in these areas.

Rust

You will need familiarize yourself with Rust to understand how Substrate is built and how to make the most of its capabilities.

If you are new to Rust, or need a brush up on your Rust knowledge, please refer to The Rust Book. You could still continue learning about Substrate without knowing Rust, but we recommend you come back to this section whenever in doubt about what any of the Rust syntax you're looking at means. Here are the parts of the Rust book we recommend you familiarize yourself with:

  • ch 1 - 10: These chapters cover the foundational knowledge of programming in Rust
  • ch 13: On iterators and closures
  • ch 18 - 19: On advanced traits and advanced types. Learn a bit about macros as well. You will not necessarily be writing your own macros, but you'll be using a lot of Substrate and FRAME's built-in macros to write your blockchain runtime.

How blockchains work

Given that you'll be writing a blockchain runtime, you need to know what a blockchain is, and how it works. The **Web3 Blockchain Fundamental MOOC Youtube video series provides a good basis for understanding key blockchain concepts and how blockchains work.

The lectures we recommend you watch are: lectures 1 - 7 and lecture 10. That's 8 lectures, or about 4 hours of video.

Quiz #3

👉 Complete Quiz #3

Substrate runtime development

High level architecture

To know more about the high level architecture of Substrate, please go through the Knowledge Base articles on Getting Started: Overview and Getting Started: Architecture.

In this document, we assume you will develop a Substrate runtime with FRAME (v2). This is what a Substrate node consists of.

assets/03-substrate-architecture.png

Each node has many components that manage things like the transaction queue, communicating over a P2P network, reaching consensus on the state of the blockchain, and the chain's actual runtime logic (aka the blockchain runtime). Each aspect of the node is interesting in its own right, and the runtime is particularly interesting because it contains the business logic (aka "state transition function") that codifies the chain's functionality. The runtime contains a collection of pallets that are configured to work together.

On the node level, Substrate leverages libp2p for the p2p networking layer and puts the transaction pool, consensus mechanism, and underlying data storage (a key-value database) on the node level. These components all work "under the hood", and in this knowledge map we won't cover them in detail except for mentioning their existence.

Quiz #4

👉 Complete Quiz #4

Runtime development topics

In our Developer Hub, we have a thorough coverage on various subjects you need to know to develop with Substrate. So here we just list out the key topics and reference back to Developer Hub. Please go through the following key concepts and the directed resources to know the fundamentals of runtime development.

Key Concept: Runtime, this is where the blockchain state transition function (the blockchain application-specific logic) is defined. It is about composing multiple pallets (can be understood as Rust modules) together in the runtime and hooking them up together.

Runtime Development: Execution, this article describes how a block is produced, and how transactions are selected and executed to reach the next "stage" in the blockchain.

Runtime Develpment: Pallets, this article describes what the basic structure of a Substrate pallet is consists of.

Runtime Development: FRAME, this article gives a high level overview of the system pallets Substrate already implements to help you quickly develop as a runtime engineer. Have a quick skim so you have a basic idea of the different pallets Substrate is made of.

Lab #4

👉 Complete Lab #4: Adding a Pallet into a Runtime

Runtime Development: Storage, this article describes how data is stored on-chain and how you could access them.

Runtime Development: Events & Errors, this page describe how external parties know what has happened in the blockchain, via the emitted events and errors when executing transactions.

Notes: All of the above concepts we leverage on the #[pallet::*] macro to define them in the code. If you are interested to learn more about what other types of pallet macros exist go to the FRAME macro API documentation and this doc on some frequently used Substrate macros.

Lab #5

👉 Complete Lab #5: Building a Proof-of-Existence dApp

Lab #6

👉 Complete Lab #6: Building a Substrate Kitties dApp

Quiz #5

👉 Complete Quiz #5

Polkadot JS API

Polkadot JS API is the javascript API for Substrate. By using it you can build a javascript front end or utility and interact with any Substrate-based blockchain.

The Substrate Front-end Template is an example of using Polkadot JS API in a React front-end.

  • Runtime Development: Metadata, this article describes the API allowing external parties to query what API is open for the chain. Polkadot JS API makes use of a chain's metadata to know what queries and functions are available from a chain to call.

Lab #7

👉 Complete Lab #7: Using Polkadot-JS API

Quiz #6

👉 Complete Quiz #6: Using Polkadot-JS API

Smart contracts

Learn about the difference between smart contract development vs Substrate runtime development, and when to use each here.

In Substrate, you can program smart contracts using ink!.

Quiz #7

👉 Complete Quiz #7: Using ink!

What we do not cover

A lot 😄

On-chain runtime upgrades. We have a tutorial on On-chain (forkless) Runtime Upgrade. This tutorial introduces how to perform and schedule a runtime upgrade as an on-chain transaction.

About transaction weight and fee, and benchmarking your runtime to determine the proper transaction cost.

Off-chain Features

There are certain limits to on-chain logic. For instance, computation cannot be too intensive that it affects the block output time, and computation must be deterministic. This means that computation that relies on external data fetching cannot be done on-chain. In Substrate, developers can run these types of computation off-chain and have the result sent back on-chain via extrinsics.

Tightly- and Loosely-coupled pallets, calling one pallet's functions from another pallet via trait specification.

Blockchain Consensus Mechansim, and a guide on customizing it to proof-of-work here.

Parachains: one key feature of Substrate is the capability of becoming a parachain for relay chains like Polkadot. You can develop your own application-specific logic in your chain and rely on the validator community of the relay chain to secure your network, instead of building another validator community yourself. Learn more with the following resources:

Terms clarification

  • Substrate: the blockchain development framework built for writing highly customized, domain-specific blockchains.
  • Polkadot: Polkadot is the relay chain blockchain, built with Substrate.
  • Kusama: Kusama is Polkadot's canary network, used to launch features before these features are launched on Polkadot. You could view it as a beta-network with real economic value where the state of the blockchain is never reset.
  • Web 3.0: is the decentralized internet ecosystem that, instead of apps being centrally stored in a few servers and managed by a sovereign party, it is an open, trustless, and permissionless network when apps are not controlled by a centralized entity.
  • Web3 Foundation: A foundation setup to support the development of decentralized web software protocols. Learn more about what they do on thier website.

Others


Author: substrate-developer-hub
Source Code: https://github.com/substrate-developer-hub/hackathon-knowledge-map
License: 

#blockchain #substrate 

Introduction to Browser Drivers in Selenium

Drivers in Selenium are a vital rather a must for Browser automation. Selenium library in Python or in any other programming language uses the particular Browser’s driver to control browsers with their actions, add functionality to it, and in all manipulate data (webpage) in it.

Contrary to the most common way of declaring a Browser’s Driver which is most common, but often may result in incompatibility issues. There are multiple ways (not so common) to install, initialize web drivers in your Python code.

Downloading the Drivers

The foremost point of error in Selenium occurs when the browser’s driver’s version doesn’t match with the browser’s version, for which compatibility issue arises. So, to start with, you must always use the driver with the same version as that of the Web Browser(Google Chrome, Mozilla Firefox, Apple Safari, or any other) which you intend to use for automation.

Downloading and installing Web Drivers is completely safe because these drivers are maintained by the Official Browser Companies and updated accordingly, for testing and automation purposes of their browser and webpages.

Check with your browser which you intend to automate for its version and download the driver from the below references accordingly:

Web BrowserDriver Download Reference
Google Chrome/ChromiumDownload
Mozilla FirefoxDownload
Microsoft EdgeDownload
Apple SafariAlready built-in

Ways to use Drivers

Let’s now look at how we can use the selenium web drivers.

1. Entering the Direct Location

  • The most popular method to use a web driver in Python Selenium code for browser automation. The reason for its popularity is the direct approach it uses, to define a driver in a script.
  • This method requires manual downloading of the web driver.

Advantage: No need to care about lengthy setup or figuring out of Environment variable
Disadvantage: Makes the code less flexible and subject to manual changes for every update

driver = webdriver.Chrome('path/to/chromedriver") 
driver = webdriver.Chrome('C://software/chromedriver.exe') #driver located at the specified location
driver = webdriver.Chrome('chromedriver.exe')  #driver located in the same directory as of the python script file
 
#other way
 
service = Service(executable_path="/path/to/chromedriver")
driver = webdriver.Chrome(service=service)

2. Environment Variable

  • If you have tried the above-mentioned method, then you may have noticed how tiring it is to note/remember the location of your installed web driver in some directory of your computer.
  • To tackle for this problem, we define the location or path of our driver in Environment Variable, once and for all. After successful definition, we do not require specifying the path location in our code, and we can code effortlessly.
  • This method also requires manual installation of the driver, as you might have known this method is used for the issue of path variable.

Advantage: No hassle of specifying the path to the driver
Disadvantage: No update functionality

To set the Environment Path Variable, go to your command prompt and type in the following command:In place of “C:\WebDriver\bin” in the below command, use the path (install location) of the driver.

setx PATH "%PATH%;C:\WebDriver\bin"

If you find this way difficult, then you may search for Environment Variable in your Windows Start Menu and click open -“Edit the system environment variables“. After that, from the pop-up window select “Environment Variables” to open another pop-up window.

From the System Variables option, select open Path and now click on New to introduce a new path variable. Paste the location of your web driver in it, then OK, OK, and finally again OK, in all windows.

Environment VariableEnvironment Variable

3. Driver Manager

The last and probably the most useful method to use is the Web Driver in your Python code. On selecting, automatic updating in Web Browser, the device only updates the browser and not the installed driver, in this case upon execution of python script the code gives error for not equal versions of the browser and driver.

Advantage: No version compatibility issues and help easily switch between multiple browsers
Disadvantage: Maybe a bit difficult to set up for beginners

Install the driver manager

pip install webdriver-manager

Import the manager

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager            # --> for Chrome
 
#from webdriver_manager.firefox import GeckoDriverManager               # --> for Firefox

Now as we have installed and imported the manager, we use it in our code like –

Use the install() method to get the location used by the manager and pass it into a loc_service class. This method informs about the location of the installed web driver by itself.

driver = webdriver.Chrome(ChromeDriverManager().install())   # --> for Chrome
 
#driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())     #--> for Firefox

For any other browser, you may check the official GitHub repository of the driver manager software.

Conclusion

That’s it for the tutorial. Contrary to the popular methods of using the web drivers in Selenium, in this tutorial you learned about the other and maybe advantageous methods to perform the same.  

Link: https://www.askpython.com/python-modules/introduction-browser-drivers-selenium

#python #selenium

Trace  Hoeger

Trace Hoeger

1635570000

Learn About PostgreSQL ODBC Driver on Windows

They asked us to write a course on the database. The theme is very simple, but you need to use all kinds of database features, such as domains, UDFs, triggers, stored procedures, etc. Et cetera. C++ with the excellent Qt library was chosen as the programming language.

#postgresql 

Seleniumのブラウザードライバーの概要

Seleniumのドライバーは、ブラウザーの自動化に不可欠です。Pythonまたはその他のプログラミング言語のSeleniumライブラリは、特定のブラウザーのドライバーを使用して、ブラウザーのアクションを制御し、ブラウザーに機能を追加し、その中のすべてのデータ(Webページ)を操作します。

最も一般的なブラウザのドライバを宣言する最も一般的な方法とは異なりますが、多くの場合、非互換性の問題が発生する可能性があります。PythonコードでWebドライバーをインストール、初期化する方法は複数あります(それほど一般的ではありません)。

ドライバーのダウンロード

Seleniumのエラーの最大のポイントは、ブラウザーのドライバーのバージョンがブラウザーのバージョンと一致しない場合に発生します。これにより、互換性の問題が発生します。そのため、まず、自動化に使用するWebブラウザ(Google Chrome、Mozilla Firefox、Apple Safariなど)と同じバージョンのドライバを常に使用する必要があります。

Webドライバーのダウンロードとインストールは完全に安全です。これらのドライバーは、公式ブラウザー会社によって維持され、ブラウザーとWebページのテストと自動化の目的でそれに応じて更新されるためです。

自動化するバージョンのブラウザを確認し、それに応じて以下のリファレンスからドライバをダウンロードしてください。

ウェブブラウザドライバーダウンロードリファレンス
Google Chrome / Chromiumダウンロード
Mozilla Firefoxダウンロード
マイクロソフトエッジダウンロード
アップルサファリすでに組み込まれています

ドライバーの使用方法

ここで、セレンWebドライバーの使用方法を見てみましょう。

1.直接の場所を入力する

  • ブラウザの自動化のためにPythonSeleniumコードでWebドライバーを使用するための最も一般的な方法。その人気の理由は、スクリプトでドライバーを定義するために使用する直接的なアプローチです。
  • この方法では、Webドライバーを手動でダウンロードする必要があります。

長所:長いセットアップや環境変数の把握を気にする必要がない
短所:コードの柔軟性が低下し、更新のたびに手動で変更される可能性があります

driver = webdriver.Chrome('path/to/chromedriver") 
driver = webdriver.Chrome('C://software/chromedriver.exe') #driver located at the specified location
driver = webdriver.Chrome('chromedriver.exe')  #driver located in the same directory as of the python script file
 
#other way
 
service = Service(executable_path="/path/to/chromedriver")
driver = webdriver.Chrome(service=service)

2.環境変数

  • 上記の方法を試した場合、コンピュータのディレクトリにインストールされているWebドライバの場所をメモ/記憶するのがいかに面倒であるかに気付いたかもしれません。
  • この問題に取り組むために、環境変数でドライバーの場所またはパスを定義します。定義が成功すると、コードでパスの場所を指定する必要がなくなり、簡単にコーディングできます。
  • この方法はパス変数の発行に使用されることをご存知かもしれませんが、この方法ではドライバーを手動でインストールする必要もあります。

利点:ドライバーへのパスを指定する手間がありません
欠点:更新機能がありません

環境パス変数を設定するには、コマンドプロンプトに移動し、次のコマンドを入力します。以下のコマンドの「C:\ WebDriver \ bin」の代わりに、ドライバーのパス(インストール場所)を使用します。

setx PATH "%PATH%;C:\WebDriver\bin"

この方法が難しい場合は、Windowsのスタートメニューで環境変数を検索し、[開く]-[システム環境変数の編集]をクリックしてください。その後、ポップアップウィンドウから「環境変数」を選択して、別のポップアップウィンドウを開きます。

[システム変数]オプションから[パスを開く]を選択し、[新規]をクリックして新しいパス変数を導入します。すべてのウィンドウで、Webドライバーの場所を貼り付けてから、[OK]、[OK]、[OK]、[OK]の順に貼り付けます。

環境変数環境変数

3.ドライバーマネージャー

最後に、おそらく最も便利な方法は、PythonコードのWebドライバーです。Webブラウザーで自動更新を選択すると、デバイスはブラウザーのみを更新し、インストールされているドライバーは更新しません。この場合、Pythonスクリプトの実行時に、コードはブラウザーとドライバーのバージョンが等しくない場合にエラーを出します。

長所:バージョンの互換性の問題がなく、複数のブラウザを簡単に切り替えることができます
短所:初心者向けに設定するのが少し難しいかもしれません

ドライバーマネージャーをインストールします

pip install webdriver-manager

マネージャーをインポートする

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager            # --> for Chrome
 
#from webdriver_manager.firefox import GeckoDriverManager               # --> for Firefox

これで、マネージャーをインストールしてインポートしたので、コードで次のように使用します–

このinstall() ãƒ¡ã‚½ãƒƒãƒ‰ã‚’使用して、マネージャーが使用する場所を取得し、それをloc_serviceクラスに渡します。このメソッドは、インストールされているWebドライバーの場所を自動的に通知します。

driver = webdriver.Chrome(ChromeDriverManager().install())   # --> for Chrome
 
#driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())     #--> for Firefox

その他のブラウザーについては、ドライバーマネージャーソフトウェアの公式GitHubリポジトリを確認できます。

結論

チュートリアルは以上です。SeleniumでWebドライバーを使用する一般的な方法とは異なり、このチュートリアルでは、同じことを実行するための他の、おそらく有利な方法について学習しました。  

リンク:https ://www.askpython.com/python-modules/introduction-browser-drivers-selenium

#python  #selenium