我看页面直接get html没有mp4的信息,视频url放在了ajax里。
用ajax拿到:import requests
from lxml import etree
import random
def main():
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'
}
ajax_headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
'Host': 'www.pearvideo.com',
'Referer': '',
'X-Requested-With': 'XMLHttpRequest'}
url = 'https://www.pearvideo.com/category_5'
base_url = 'https://www.pearvideo.com/'
r = requests.get(url=url, headers=headers)
html = etree.HTML(r.text)
videos = html.xpath('//li[@class="categoryem"]/div/a/@href')
for video in videos:
mrd = random.random()
video_page = f'https://www.pearvideo.com/videoStatus.jsp?contId={video[-7:]}&mrd={mrd}'
ajax_headers['Referer'] = f'{base_url}{video}'
r = requests.get(video_page, headers=ajax_headers)
video_url = r.json()['videoInfo']['videos']['srcUrl']
print(video, video_url)
if __name__ == '__main__':
main()
|