First code, then analyze:
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
while True:
chromeOptions = webdriver.ChromeOptions()
browser = webdriver.Chrome('C:\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe', options=chromeOptions) #浏览器驱动
browser.delete_all_cookies() # 删除cookie
browser.get("https://www.youtube.com/watch?v=cHaCsmfMLzg") #视频地址
element = WebDriverWait(browser, 15).until( #等待播放按钮能够被加载并且能够被点击,15s后如果还没加载完成并且不满足被点击的条件,就抛出异常
EC.element_to_be_clickable((By.XPATH, '//*[@id="bilibiliPlayer"]/div[1]/div[1]/div[8]/video'))
)
element.click()
print(browser.get_cookies())
time.sleep(100)# 等待时常
browser.quit()
Code analysis:
1. Call to library
I’m calling this vault, and I won’t install it.
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
I’ll be asked, why don’t you just import a serenium library? Get used to it and not make your code redundant, or when you pack, pack up the whole pool. Remember, that custom is important!
2. Browser debug driver
chromeOptions = webdriver.ChromeOptions()
browser = webdriver.Chrome('C:\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe', options=chromeOptions) #浏览器驱动
Here you have to download the browser debug drive, like your browser version.
Website:
- Shrom browser Webdriver: Point here.
- Firefox webdriver (geckoderiver.exe): Point here.
- Microsoft Edge: Stick here.
- Apple Safari : Click it
It is then placed in the browser root directory, and you can put the drive under the browser root directory to the code.
browser = webdriver.Chrome('驱动路径', options=chromeOptions) #浏览器驱动
3. Delete cookies
browser.delete_all_cookies() # 删除cookie
Cookie does not mean “concrete” as it meant, but rather a simple text file that is stored in the client’s machine, which is linked to a specific Web document, saves information on each user’s machine when the client visits this web document, and when the client again accesses this Web document, it can be used for that document. Because “Cookie” has magical features that can be stored on the client’s machine, it helps us to record user-specific information without having to use complex CGI programs. For example, one Web site may produce a single ID for every visitor, and then save it in the form of a Cookie file. If you use a browser to access this Web document, you see all the files stored on hard disks that are available at Cookie’s own location.
In order to avoid repeated visits, Cookie recorded the situation.
4. Video address
browser.get(" 要访问的视频地址") #视频地址
Paste the video address that is to be visited directly, then.
5. Automatically play
element = WebDriverWait(browser, 15).until( #等待播放按钮能够被加载并且能够被点击,15s后如果还没加载完成并且不满足被点击的条件,就抛出异常
EC.element_to_be_clickable((By.XPATH, '//*[@id="bilibiliPlayer"]/div[1]/div[1]/div[8]/video'))
)
element.click()
Step 1: Sets the waiting times for loading, and the length of the network setting. Step 2: Get to the play button, this is where you play from station B. Other websites, F12, click on it, then click on the play button, and you can get it by code.
![]()
6. Loaded successful, output cookies
print(browser.get_cookies())
If you load it, we’ll give the corresponding feedback. So let’s just get out of cookies to see the feedback.
7. Set the duration of each video view
time.sleep(100)# 等待时常
This one should be under 30 seconds, or it’ll be sealed too quickly.
8. Close browser
browser.quit()
Note: This paper, which tends to teach Python, does not recommend that it should really be used for access, because the method of doing so is an IP pool where too few brushes are actually able to raise video-playing volumes in a short time. I don’t say, it would be fair to draw tens of thousands of people on B station who use hard-core video writers, and for those platforms they use their usual means of running, you will only add PVs, and no more user stickiness to the UV.
I’ve been asked. What are you talking about?
24 hours an hour, 60 minutes an hour, two more views a minute, and one ip a day increases the number of 2880. Better than you do manually. High quality content adds to sticky users, with the amount of play on software being painted, which is always infrequently spent, and urges step by step to become a high-quality video author.
It’s written at the end:
Name: “A student who is currently a bi-school student and who is expected to study, program, love technology, like sharing, have no knowledge, hoping that my share will help you.” What it means: I think one day I’ll be able to do whatever I want, not always lower myself to life, but rather to keep family rich, instead of living for the sake of survival.” “The world panics. It’s just silver.
The main contents of the article:
Python, C++, C-languages, JAVA, C# language curriculum ACM solution, templates, algorithms, etc., mainly data structure, mathematics and graphics Design models, databases, computer networks, operating systems, principles of computer formation Python reptiles, in-depth learning, machine learning, computer departments408All the study courses.
It is still being updated to focus on not getting lost.
未经允许不得转载:萌萌Apprentissage » Python achieves video-visiting (Python pedagogic articles) on YouTube, B station, Achie art and watermelons
Python batches to extract mainstream search engine pictures
Python's word crawling across 100 degrees.
PythonTaiichi Taipei Artificial Intelligence Tensoflow Graphic Processing
Selenium with Tor Browser using Python
I'm gonna get you a new one, shell.cloud.google on the line.