In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to use Python+selenium to achieve automatic video upload and release of interesting headlines". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how to use Python+selenium to achieve automatic video upload and release of interesting headlines".
Effect display
Material display
One is a video, and the other is a cover with a pixel size of no less than the video.
Implement procedure calls to enabled browsers
By calling an enabled browser, you can skip each login process directly.
You can refer to the supplementary content for the usage.
From selenium import webdriveroptions = webdriver.ChromeOptions () options.add_experimental_option ("debuggerAddress", "127.0.0.1 options.add_experimental_option 5003") driver = webdriver.Chrome (options = options) upload video and cover
For more information on how to use the upload function, please refer to the supplementary content.
# upload video driver.find_element_by_xpath ('/ / input [@ type= "file"]') .send_keys (path_mp4) # wait for video upload completed while True: time.sleep (3) try: driver.find_element_by_xpath ('/ / * [contains (text (), "upload successful")]') break Except Exception as e: print ("video is still uploading") print ("video has been uploaded!") # add cover time.sleep (1) driver.find_element_by_xpath ('/ / * [@ class= "el-upload"]'). Click () time.sleep (1) driver.find_element_by_xpath ('/ / * [text () = "Custom cover"]'). Click () time.sleep (1) driver.find_element_by_xpath ('/ / * [text () = "Select Picture"] /. /.. / / Input [@ type= "file"]') .send_keys (path_cover) time.sleep (3) driver.find_element_by_xpath ('/ / * [text () = "certainty"]') .click () complete source code display import seleniumfrom selenium import webdriverimport pathlibimport timefrom selenium.webdriver.common.keys import Keys# basic information # video storage path catalog_mp4 = r "C:\ Users\ Administrator\ Desktop\ video release" # Video description describe = "watching Spider-Man in naked 3D # funny # Movie # Visual shock" time.sleep (10) options = webdriver.ChromeOptions () options.add_experimental_option ("debuggerAddress" "127.0.0.1 options 5003") driver = webdriver.Chrome (options = options) path = pathlib.Path (catalog_mp4) # Video address acquisition path_mp4 = "" for i in path.iterdir (): if (".mp4" in str (I)): path_mp4 = str (I) Break;if (path_mp4! = ""): print ("check video path:" + path_mp4) else: print ("No video path checked, program terminated!") Exit () # cover address acquisition path_cover = "" for i in path.iterdir (): if (".png" in str (I) or ".jpg" in str (I)): path_cover = str (I); break;if (path_cover! = "): print (" cover path checked: "+ path_cover) else: print (" cover path not checked, program terminated! ") Exit () def publish_qutoutiao ():''function: publish interesting headline video''# enter the creator's page And upload the video driver.get ("https://mp.qutoutiao.net/publish-content/video") time.sleep (2) driver.find_element_by_xpath ('/ / input [@ type=" file "]') .send_keys (path_mp4) # waiting for the video to be uploaded while True: time.sleep (3) try: driver.find_element_by_ Xpath ('/ / * [contains (text ()) "uploaded successfully")]') break Except Exception as e: print ("video is still uploading") print ("video has been uploaded!") # enter the title driver.find_element_by_xpath ('/ / * [@ placeholder= "content title 5-30 words]'). Clear () time.sleep (2) driver.find_element_by_xpath ('/ / * [@ placeholder=" content title 5-30 words]') .send_keys (describe) # enter description information time.sleep (1) driver.find_element_by_xpath ('/ / textarea'). Clear () time.sleep (2) driver.find_element_by_xpath ('/ / textarea'). Send_keys (describe) # Select category time.sleep (1) driver.find_element_by_xpath ('/ / * [@ placeholder= "Please select category"]'). Click () time.sleep (1) driver.find_element_by_xpath ('/ / * [ Text () = "movie"]'). Click () time.sleep (1) driver.find_element_by_xpath ('/ / * [text () = "category:"]'). Click () time.sleep (1) # input label time.sleep (1) driver.find_element_by_xpath ('/ * [@ class= "content-tag"] / / input') .click () time. Sleep (2) driver.find_element_by_xpath ('/ / * [@ class= "content-tag"] / / input'). Send_keys ("visual shock") time.sleep (2) driver.find_element_by_xpath ('/ / * [@ class= "content-tag"] / / input'). Send_keys (Keys.ENTER) time.sleep (2) driver.find_element_by_xpath ('/ / * [@ class= "content-tag"] / / input'). Send_keys ("funny") time.sleep (2) driver.find_element_by_xpath ('/ / * [@ class= "content-tag"] / / input'). Send_keys (Keys.ENTER) time.sleep (2) driver.find_element_by_xpath ('/ / * [@ class= "content-tag"] / / input'). Send_keys (movie) time. Sleep (2) driver.find_element_by_xpath ('/ / * [@ class= "content-tag"] / / input'). Send_keys (Keys.ENTER) # add cover time.sleep (1) driver.find_element_by_xpath ('/ / * [@ class= "el-upload"]'). Click () time.sleep (1) driver.find_element_by_xpath ('/ / * [text () = " Custom cover "]'). Click () time.sleep (1) driver.find_element_by_xpath ('/ / * [text () =" Select a picture "] /.. /.. / input [@ type=" file "]') .send_keys (path_cover) time.sleep (3) driver.find_element_by_xpath ('/ / * [text () =" confirm "]') .click () # manually check and publish # time.sleep (3) # # Click publish # driver.find_element_by_xpath ('/ / * [text () = "publish"]'). Click () # start to execute video publishing publish_qutoutiao () supplementary Python+selenium operation enabled chrome browser
First add this parameter to the target of the chrome shortcut.
The front represents the debug port, which you can use freely, and the back points to a new folder for storing user data.
Note: if the following parameters are not added, port enablement seems to fail, and no reason has been found at present.
-remote-debugging-port=5003-user-data-dir= "C:\ Py_selenium\ auto"
Then double-click the shortcut to open the browser, and now the browser can be controlled.
If you are not sure whether the port is enabled, you can check the port enablement in cmd using the following method.
C:\ Users\ Administrator > netstat-ano | findstr 5003 TCP 127.0.0.1 netstat 5003 127.0.0.1 findstr 53546 FIN_WAIT_2 12180 TCP 127.0.1 TCP 0 TCP 127.0.0.1 FIN_WAIT_2 12180 TCP 127.0 . 0.1:5003 127.0.0.1:53859 TIME_WAIT 0 TCP 127.0.0.1:5003 127.0.0.1:53900 FIN_WAIT_2 12180 TCP 127.0.0.1:5003 127.0.0.1:53901 TIME_WAIT 0 TCP 127.0.0.1:53546 127.0.0.1: 5003 CLOSE_WAIT 15540 TCP 127.0.0.1:53858 127.0.0.1:5003 CLOSE_WAIT 9108 TCP 127.0.0.1:53900 127.0.0.1:5003 CLOSE_WAIT 16320
Control enabled browsers by accessing the debug port.
Another method for from selenium import webdriver# to import chrome parameters # from selenium.webdriver.chrome.options import Options# options = Options () options = webdriver.ChromeOptions () options.add_experimental_option ("debuggerAddress", "127.0.0.1 options 5003") driver = webdriver.Chrome (options = options) print (driver.title)
Run the effect diagram:
Python+selenium implements automatic import and upload of external files
At first, I thought it was necessary to operate the windows file window to import external files, but later I found that it was not so troublesome, as long as I passed a local path to the uploaded elements of the file, which was an input type.
Right-click on the element to check to see the corresponding element.
Then send_keys () passes in the path.
Driver.find_element_by_xpath ('/ / input [@ type= "file"]') .send_keys ('C:\\ Users\\ Administrator\\ Desktop\\ file .zip') above are all the contents of this article entitled "how to use Python+selenium to automatically upload and publish videos of interesting headlines". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.