Python + Selenium: How to Use? [SE01]
by - Thursday, January 1, 1970 at 12:00 AM
Hello fellow brothers in the community.
I'll give you an introduction to Python + Selenium.
First, a few remarks:
1. I am Chinese, I just found out about this forum, I like it very much. After I successfully registered, I need to upgrade my account level, after contacting the administrator, the administrator did not ask for my money, on the contrary, the management Very generously gifted to my highest tier members. This moved me very much.
2. In the current world, everything has to do with money, and I don't want to do that in the next knowledge sharing. In China, there is an old saying, "Give someone a rose, and leave a fragrance in your hand". Translated into English, it roughly means: "If you give roses to others, your hands will have fragrance." Therefore, I feel that in the community , money is not very important.
3. There are many people in the community with better technology than me, so I must always be humble and cautious. If there is an incorrect method, I need everyone to communicate.
4. Most important: If you benefit from learning in the community, then you make a lot of money and have extra time, please give back to the community as well.

By:  breached.to -> tianyi2001 [2022/07/28]

***
The development environment, I use Pycharm, of course, you can use free vscode, or other development tools.

The specific development environment configuration, I am not going to explain in detail here, because it may lead to too much text in the post and affect viewing.
***

一、First, let's get acquainted with the general flow of the previous code.

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# 2022-07-28
# Breached.to Bullet Class:
# THE FAST ONLINE VERSION 1.0CB

# Import selenium package
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

if __name__ == '__main__':
    """
    Create a selenium object, then you can use the methods of this object, if you don't understand, you can ignore it, copy and paste with me
    """
    # Custom option parameters
    options = webdriver.ChromeOptions()
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option("excludeSwitches", ["enable-logging"])
    options.add_experimental_option('useAutomationExtension', False)
    options.add_argument('--disable-blink-features=AutomationControlled')
    options.add_argument('disable-cache')
    options.add_argument('-ignore-certificate-errors')
    options.add_argument('-ignore -ssl-errors')

    # Download the Chrome kernel locally, then, we load it
    _chromePath = r"r:\chromedriver.exe"
    # Use Service(), initialize
    chromeService = Service(_chromePath)
    # The only thing to note about the two parameters here is options. In the front, we customized these options, then DRIVER will use it as we customized
    DRIVER = webdriver.Chrome(options=options, service=chromeService)

    # We use https://www.bing.com as an example
    BASE_URL = "https://www.bing.com"
    DRIVER.get(BASE_URL)

If nothing else, you should now see that you have Bing turned on by controlling Selenium.

This example is very simple, don't think it's very simple, just have the courage to keep trying. Even though it's just less than 50 lines of code, it will take you on a journey and drive far away.
Reply
WOW ... That's really nice of pompompurin :pomlove:
:pomlove: Thank you @FederalAgentBrad for the VIP Rank and Thank you @tty for the GOD Rank.
Thank you @nan9e for the gift >.<
:pomlove:
Reply
(July 28, 2022, 03:51 AM)cod Wrote: WOW ... That's really nice of pompompurin :pomlove:


Yes, it's very generous, which moves me very much.

Glad to be here :)
Reply
Hi and thank for this amazing code. Can you make a list that contain the list on which to read first and have some more detail about the line of code you write or even make a video about this. Thats would be much appriciate mate. But again just asking if you dont have time to do then its totally fine.  :heart:
Reply
(July 29, 2022, 07:58 AM)longvanren Wrote: Hi and thank for this amazing code. Can you make a list that contain the list on which to read first and have some more detail about the line of code you write or even make a video about this. Thats would be much appriciate mate. But again just asking if you dont have time to do then its totally fine.  :heart:


Yes, I have this idea, it's just that I don't have a lot of time personally. I need to work during the day, and I usually do it after I get off work and take up the weekends.

Thank you so much for your encouragement. I will do my best. :)
Reply
İ NEW STARTED PYTHON
Reply
Ye sick post <3
:pomlove:  @Rayzers   :pomlove: 
Reply
Why would you use if __name__ == '__main__':
Reply
(November 27, 2022, 12:16 AM)Max Wrote: Why would you use if __name__ == '__main__':

this sets the priority of python scripts and imported modules


(November 27, 2022, 12:16 AM)Max Wrote: Why would you use if __name__ == '__main__':


simplifying...

if __name__ == '__main__' ... control the scope of execution
Reply
I was using this to buy tickets. (not scalping just for me). One thing that I can pass to you is get a tool for getting absolute paths if the website is kinda clingy. There are multiple but I use Xpath.
Reply


 Users viewing this thread: Python + Selenium: How to Use? [SE01]: No users currently viewing.