代码拉取完成,页面将自动刷新
import codecs
import json
import requests
import re
import threadpool
import ip
import jiexi
from fake_useragent import UserAgent
import csv
import pandas as pd
import numpy as np
import sys
ua = UserAgent()
session = requests.session()
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 "
"Safari/537.36 SLBrowser/7.0.0.1071 SLBChan/30 "
}
video_headers = {'Connection': 'close'}
proxy = {
"http": "http://117.41.186.201:888"
}
print(proxy)
rows = []
def get_video(pg):
d = session.get("https://www.o8tv.com/api.php/provide/vod/?ac=detail&h=24&pg={}".format(pg), headers=None,
proxies=proxy, timeout=5)
d_js = d.json()
print(d_js["page"], "页")
for single in d_js["list"]:
singlerow = (single["vod_id"], single["type_id"], single["vod_name"]
, single["vod_class"], single["vod_pic"],
single["vod_actor"], single["vod_blurb"], single["vod_remarks"],
single["vod_area"], single["vod_score_all"], single["vod_play_url"])
rows.append(singlerow)
print(singlerow)
def run():
r = session.get("https://www.o8tv.com/api.php/provide/vod/?ac=detail&h=24", headers=None,
proxies=proxy, timeout=5)
pagecount = r.json()["pagecount"]
if r.status_code == 200:
for pg in range(1, pagecount+1):
get_video(pg)
#
pool = threadpool.ThreadPool(10) # 线程池设置,最多同时跑两个线程
tasks = threadpool.makeRequests(get_video, range(1, pagecount + 1))
# makeRequests构造线程task请求,第一个参数是线程函数,第二个是参数数组
[pool.putRequest(task) for task in tasks]
# 列表推导式,putRequest向线程池里加task,让pool自己去调度task
pool.wait() # 等所有任务结束
headers22 = ['vod_id', 'type_id', 'vod_name', 'vod_class', 'vod_pic', 'vod_actor', 'vod_blurb',
'vod_remarks', 'vod_area', 'vod_score_all', 'vod_play_url']
f = codecs.open("chengzisee.csv", 'wb', "utf8")
writer = csv.writer(f)
writer.writerow(headers22)
# 多组数据存放list列表里面
datas = rows
writer.writerows(datas)
f.close()
print("电影结束")
else:
print("errror")
if __name__ == '__main__':
run()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。