import requests
from lxml import etree
from prettytable import PrettyTable
host = "http://www.okzy.co"
rooturl = "/?m=vod-index-pg-{}.html".format(1)
response = requests.get(host+rooturl)
response.encoding = 'utf-8'
if response.status_code==200:
print("==========爬虫工作开始==========")
page_index = response.text
page_index_xp = etree.HTML(page_index)
page_index_xp_title = page_index_xp.xpath("//div[@class='xing_vb']/ul/li/span[@class='xing_vb4']/a/text()")
page_index_xp_titleurl = page_index_xp.xpath("//div[@class='xing_vb']/ul/li/span[@class='xing_vb4']/a/@href")
page_index_num = 0
for p_i_title in page_index_xp_title:
p_i_titleurl = host+page_index_xp_titleurl[page_index_num]
table_index = PrettyTable(['《{}》'.format(p_i_title.strip())])
table_info = PrettyTable(['资源名称','播放地址'])
page_index_num+=1
page_sec_info = requests.get(p_i_titleurl)
if page_sec_info.status_code==200:
page_sec = page_sec_info.text
page_sec_xp = etree.HTML(page_sec)
page_sec_xp_playurl = page_sec_xp.xpath("//div[@class='vodplayinfo']//ul/li/text()")
for piurl in page_sec_xp_playurl:
piname = piurl.split("$")[0]
pilink = piurl.split("$")[1]
table_info.add_row([piname,pilink])
htmltemp = '''<video autoplay="autoplay" controls="controls" src="{}"></video>'''.format(pilink)
table_index.add_row([table_info])
print(table_index)
else:
print("==========爬虫不能正确工作,原因:{}==========".format(response.status_code))
转载请注明原文地址:https://ipadbbs.8miu.com/read-9803.html