Commit ec9c8a86 by BellCodeEditor

save project

parent 595d1f8e
Showing with 104 additions and 7 deletions
#导入包
import requests
import re
import os
import urllib.request
#伪装浏览器
headers = {}
#爬取网站地址
url = 'http://www.pearvideo.com/category_8'
#页面代码
pageText = requests.get(url = url, headers = headers).text
#print (pageText)
#获取视频id .*?匹配所有
reg = '<a href="(.*?)" class="vervideo-lilink actplay">'
video_id = re.findall(reg,pageText)
#print(video_id)
#拼接地址
video_url=[]
#开始地址
starturl='http://www.pearvideo.com'+''
#重
for vid in video_id:
#+号是拼接字符串
newurl=starturl+'/'+vid
#print(newurl) #视频url地址 http://www.pearvideo.com/video 1739606
video_url.append(newurl)
# print(newurl)
for purl in video_url:
#split 分割字符串
video_numId = purl.split('_')[1]
#伪装浏览器
headersl = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
'Referer':'http://www.pearvideo.com/'+purl
}
#包的链接
# https://www.pearvideo.com/videoStatus.jsp?contId=1739780
#视频存储链接
# https://video.pearvideo.com/mp4/short/20210824/1629946971619-15752877-hd.mp4
#视频下载链接
# https://video.pearvideo.com/mp4/short/20210824/cont-1739780-15752877-hd.mp4
videoHref = 'https://www.pearvideo.com/videoStatus.jsp?contId='+video_numId
# print(videoHref)
videoUrl = requests.get(url=videoHref, headers=headersl).json()
# print(videoUrl)
if videoUrl['resultCode']=='1':
video = videoUrl['videoInfo']["videos"]["srcUrl"]
# print(video)
video2 = video.replace(video.split('/')[-1].split('-')[0],'cont-%s'%video_numId)
#print(video2)
#视频标题
video_title =requests.get(url=newurl,headers=headers).text
reg='<h1 class="video-tt">(.*?)</h1>'
video_name = re.findall(reg,video_title)
print(video_name)
#下载视频
urllib.request.urlretrieve(video2,video_name[0]+'.mp4')
print("下载完成")
\ No newline at end of file
...@@ -12,25 +12,48 @@ background = pygame.image.load('bg.png') ...@@ -12,25 +12,48 @@ background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') right = pygame.image.load('right.png')
food = pygame.image.load('apple.png') food = pygame.image.load('apple.png')
body = pygame.image.load('body.png') body = pygame.image.load('body.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down=pygame.image.load('down.png')
x,y=240, 120 x,y=240, 120
position=[(180,90),(180,120,),(210.120),(x,y)] position=[(180,90),(180,120,),(210.120),(x,y)]
snake_head=right
setheading='right'
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
x+=30 if event.type==locals.KEYDOWN:
body1x+=30 if event.key==locals.K_RIGHT and setheading!='left':
setheading='right'
snake_head=right
if event.key==locals.K_LEFT and setheading!='right':
setheading='left'
snake_head=left
if event.key==locals.K_UP and setheading!='down':
setheading='up'
snake_head=up
if event.key==locals.K_DOWN and setheading!='up':
setheading='down'
snake_head=down
if setheading=='right':
x+=30
if setheading=='left':
x-=30
if setheading=='up':
y-=30
else:
y+=30
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right, (x,y)) screen.blit(snake_head,position[-1])
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
screen.blit(body, (body1x,body1y)) for i in range(len(position)-1):
screen.blit(body, (180, 120)) screen.blit(body,position[i])
screen.blit(body, (180, 90))
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (360, 300))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.tick(3)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment