用xpath爬取某视频网站的源视频地址,运行都没问题,结果也没报错,偏偏爬下来是个空列表[],附上源代码
import requests
import lxml
from lxml import etree
# 获取当前分页的所有视频地址并存放在urllist列表中
headers={'Cookie':'kt_is_visited=1; Hm_lpvt_762db7441df8f5cc6e82d0d959c93d8f=1556969491; Hm_lvt_762db7441df8f5cc6e82d0d959c93d8f=1556967744; kt_tcookie=1; kt_ips=121.238.219.145; kt_qparams=sort_by%3Dvideo_viewed%26from%3D456; __atuvc=6%7C18; __atuvs=5ccd7150d7cb4d2a005; PHPSESSID=5os69ok886ohqdmhghst50r5a5',
        'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Upgrade - Insecure - Requests':'1',
        'Host':'www.cqwoool.com',
        'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15',
        'Accept - Language': 'zh - cn',
        'Accept - Encoding': 'gzip, deflate',
        'Connection': 'keep - alive'}
pages=range(1,2)
urllist=[]
for page in pages:
    url = 'http://www.cqwoool.com/most-popular/'+page.__str__()+'/'
    html=requests.get(url,headers=headers)
    html_etree=etree.HTML(html.text)
    href_singlemoviehtml=html_etree.xpath('//*[@id="list_videos_common_videos_list_items"]/div/a/@href')
    urllist.extend(href_singlemoviehtml)
# print(urllist)
# 获取指定单个页面中的视频地址
for single_url in urllist:
    headers2={'Cookie':'kt_ips=121.238.219.145; Hm_lpvt_762db7441df8f5cc6e82d0d959c93d8f=1556973469; Hm_lvt_762db7441df8f5cc6e82d0d959c93d8f=1556967744; kt_is_visited=1; __atuvc=9%7C18; __atuvs=5ccd7f85b3a82678002; kt_tcookie=1; kt_qparams=id%3D5578%26dir%3Db0f2dfb7547977b1329f0980d3f5bcad; PHPSESSID=5os69ok886ohqdmhghst50r5a5',
              'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
              'Accept - Encoding': 'gzip, deflate',
              'Upgrade - Insecure - Requests': '1',
              'Host': 'www.cqwoool.com',
              'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15',
              'Accept - Language': 'zh - cn',
              'Connection': 'keep - alive'}
    html_single=requests.get(single_url,headers=headers2)
    html_single_etree=etree.HTML(html_single.content)
    href_singlemovie=html_single_etree.xpath('//*[@id="kt_player"]/div[2]/video/@src')
    print(href_singlemovie)
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐