Really? , Why do so many people watch games , I sent it twice. It adds up to one Mimi …
Come on come on , Not the whole game , You don't like it anyway ~
Today, let's try to climb the hot girls in the headlines , I don't know if I can stand it ~
1、 Environment used
2、 Third party modules to be used
Since you don't like my wordiness , But what about the process , I'll still write it for you , So I listed it separately .
1、 Website analysis ( Clear requirements )
2、 Code implementation process
If you are learning Python In the process of learning, I don't know the learning direction , How to learn , There is no good system of learning materials 、 No one exchanges answers and so on , You can private me , I'm ready for everyone .
First, import the module
import requests
from selenium import webdriver
Go to browser settings
options = webdriver.ChromeOptions()
1、 structure embedUrl https://www.ixigua.com/embed?group_id=7029910152576926238
group_id = input(" Please enter the video you want to download id:")
url = 'https://www.ixigua.com/embed?group_id=' + group_id
Headless browser
options.add_argument("--headless")
Add a disguise
options.add_argument('User-Agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36"')
2、 Use selenium Visit the link
driver: browser
driver = webdriver.Chrome(executable_path="chromedriver.exe", options=options)
Open a web page
Drive configuration : Code operates as a middleman in the browser
driver.get(url)
An implicit wait : Wait up to five seconds If the load is finished in one second Carry on
driver.implicitly_wait(5)
3、 Extract video link address
info = driver.find_elements_by_xpath('//*[@id="player_default"]/xg-controls/xg-definition/ul/li[1]')
video_url = info[0].get_attribute("url")
4、 Splicing video link address
video_url = 'http:' + video_url
5、 Use requests Send a request And get video binary data
video_data = requests.get(video_url).content
with open('1.mp4', mode='wb') as f:
f.write(video_data)
python Answering question consulting Learning exchange group 2:660193417###
import requests
from selenium import webdriver
# Go to browser settings
options = webdriver.ChromeOptions()
# 1. structure embedUrl https://www.ixigua.com/embed?group_id=7029910152576926238
group_id = input(" Please enter the video you want to download id:")
url = 'https://www.ixigua.com/embed?group_id=' + group_id
# Headless browser
options.add_argument("--headless")
# Add a disguise
options.add_argument('User-Agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36"')
# 2. Use selenium Visit the link
# driver: browser
driver = webdriver.Chrome(executable_path="chromedriver.exe", options=options)
# Open a web page
# Drive configuration : Code operates as a middleman in the browser
driver.get(url)
# An implicit wait : Wait up to five seconds If the load is finished in one second Carry on
driver.implicitly_wait(5)
# 3. Extract video link address
info = driver.find_elements_by_xpath('//*[@id="player_default"]/xg-controls/xg-definition/ul/li[1]')
video_url = info[0].get_attribute("url")
# 4. Splicing video link address
video_url = 'http:' + video_url
# 5. Use requests Send a request And get video binary data
video_data = requests.get(video_url).content
with open('1.mp4', mode='wb') as f:
f.write(video_data)
print(" Climb to success !!!")
# Leave an error , See if everyone is smart enough to find out