


Install chrome and use selenium to realize automatic barrage of Kuaishou
Use python's selenium package to realize the automatic barrage process of Kuaishou
1. Prepare the chrome browser and the corresponding version of the webdriver driver
2. python Install the selenium package
3. Log in to Kuaishou in chrome to analyze the process of posting barrages
4. Code implementation
5. Run
1. Install the Google Chrome download driver
##Google official website
(Google Access Assistant plug-in: Link: https://pan.baidu.com/s/1XFazQydGjFyy-UZKTwqjgQ Extraction code: 30kz)
The downloaded one is called Google Access Assistant_v2.3.0.crx extension packageInstallation method:
Open the chrome browser, more tools->Extensions-> Just drag it here -> You need to set one of the two URLs as the homepage to use the Chrome browser normally.
Install the webdriver that matches the browser version
1. Open Google Chrome and enter chrome in the address bar ://version/ View version information Result similar to the following:Google Chrome 79.0.3945.117 (official version) (64-bit)Revision 04f0a055010adab4484f7497fbfdbf312c307f1d-refs/branch -heads/3945@{#1019}
Operating system Windows 10 OS (Build 10240.16384)
##2. Select the appropriate version Driver download,
Download address: http://chromedriver.storage.googleapis.com/index.html
3. Place chromedriver.exe in the Python environment directory
For example: D:\server\Python\Python37\chromedriver.exe
## 2. Install selenium package in pythonCommand line: pip install selenium
Compiler pycharm: setting->Project Interpreter just add selenium
3. Log in to Kuaishou in Chrome to analyze the process of posting barrages
Enter the content here in the live broadcast room, and then click send. Therefore, the code must select this input box, write the content operation, and be able to select the send button, and then click the operation.
4. Code implementationfrom selenium import webdriver
import time# Import class libraryoptions = webdriver.ChromeOptions()
In addition to the above comments, you should also pay attention to the use of css selectors:
options.add_argument(r"user-data-dir=C:\Users\lxs\AppData\Local\Google\Chrome\User Data")
driver=webdriver.Chrome(options=options)
driver.get('https://live.kuaishou.com/u/......?csr=true')#Open a page
time .sleep(2) #Slow for two seconds to allow the web page to load completely
for i in range(0,10): #Loop 10 times, enter 666 10 times
#Through chrome’s css selector
input = driver.find_element_by_css_selector('#app > div.live-detail > div.liveroom-sidebar.light > div.chat > div.chat-actions > div.chat-input > div > textarea')
input.send_keys('六六六') #Input 3 sixes to the element
submit = driver.find_element_by_css_selector('#app > div.live-detail > div.liveroom- sidebar.light > div.chat > div.chat-actions > div.chat-input > div > button')
submit.click() #Click operation
Press F12 and select the option in the upper left corner to directly select the required elements on the page. Do the following: right-click copy->selector (because the code is selected in this mode)
5. Run the codeRun result:
The program opens chrome by itself and visits the live broadcast room. The six here is what the program itself typed. According to the code, the input submission is looped 10 times in total.
Summary:
Because the actual simulated login has not been written yet, it can only be achieved through this method, and the speed is also slow. Really simulated login will be many times faster. This method is suitable for situations where simulated login cannot be achieved.
The above is the detailed content of Install chrome and use selenium to realize automatic barrage of Kuaishou. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PyCharm installation tutorial: Easily learn how to install Selenium, specific code examples are needed. As Python developers, we often need to use various third-party libraries and tools to complete project development. Among them, Selenium is a very commonly used library for automated testing and UI testing of web applications. As an integrated development environment (IDE) for Python development, PyCharm provides us with a convenient and fast way to develop Python code, so how

Laravel development: How to use LaravelDusk and Selenium for browser testing? As web applications become more complex, we need to ensure that all parts of it function properly. Browser testing is a common testing method used to ensure the correctness and stability of an application under various browsers. In Laravel development, you can use LaravelDusk and Selenium for browser testing. This article will introduce how to use these two tools to test

Using Selenium and PhantomJS in Scrapy crawlers Scrapy is an excellent web crawler framework under Python and has been widely used in data collection and processing in various fields. In the implementation of the crawler, sometimes it is necessary to simulate browser operations to obtain the content presented by certain websites. In this case, Selenium and PhantomJS are needed. Selenium simulates human operations on the browser, allowing us to automate web application testing

Overview of How to Use Selenium for Web Automation Testing: Web automation testing is a vital part of the modern software development process. Selenium is a powerful automated testing tool that can simulate user operations in a web browser and implement automated testing processes. This article will introduce how to use Selenium for web automation testing, and come with code examples to help readers get started quickly. Environment preparation Before starting, you need to install the Selenium library and web browser driver

1. Slider verification idea The slider object of the object under test looks like this. Relatively speaking, it is a relatively simple form. You need to drag the puzzle on the left through the slider below and embed it into the empty slot on the right to complete the verification. To automate this verification process, the key point is to determine the distance the slider slides. According to the above analysis, the key point of verification is to determine the sliding distance of the slider. But a seemingly simple requirement is not simple to complete. If you use natural logic to analyze this process, it can be broken down as follows: 1. Locate the position of the puzzle on the left. Since the shape and size of the puzzle are fixed, you only need to locate the distance between its left border and the left side of the background image. (Actually, in this example, the starting position of the puzzle is also fixed, saving

1. First open the Kugou music playback interface. 2. Then click Comments on the playback interface. 3. Enter the comment and you can see the comment option above. 4. Finally, choose to close the review and return to the playback interface.

In the software Youku, we can freely turn on and off the barrage, and we can also adjust the display settings of the barrage. Some users don’t know where Youku’s barrage settings are. The article introduces how to set up the mobile phone and computer. The editor below will introduce you to the barrage setting method. Let’s take a look at this article. Where to set up the Youku barrage mobile version? 1. Enter any Youku video, click on the middle of the video, and then click on the full screen on the lower right. 2. Click in the middle of the video again and click on the three dots on the upper right. 3. You can see [Barrage Settings] on the upper right. 4. Click to enter to set up the barrage display. PC version 1. Enter Youku and select any video. 2. In the line below the video, you can see the [pop-up] of the settings icon in the lower right corner. 3. Click to play

With the rapid development of Internet technology, Web applications are increasingly used in our daily work and life. In the process of web application development, crawling web page data is a very important task. Although there are many web scraping tools on the market, these tools are not very efficient. In order to improve the efficiency of web page data crawling, we can use the combination of PHP and Selenium. First, we need to understand what PHP and Selenium are. PHP is a powerful
