关于绕过cloudflare时的问题
在请求低端影视 - 超清在线视频站 (ddys.pro)时,想使用python调用idm下载视频,发现是cloudflare,然后使用cloudscrper库能访问到第一层主页面,然后进入每一个视频页面,同样的方法请求可以拿到视频下载地址的时候返回{"err":"error3.4"},两次请求用的都是cloudscrper库绕过,但是第二次就不成功,换了curl_cffi库的request请求也返回{"err":"error3.4"},怎么解决import json
from lxml import etree
from subprocess import call
import cloudscraper
def parse(url):
scraper = cloudscraper.create_scraper(
browser={
'browser': 'chrome',
'platform': 'android',
'desktop': False
}
)
response = scraper.get(url)
tree = etree.HTML(response.text)
hrefs = tree.xpath('.//main/div/article/div/div/h2/a/@href')
for href in hrefs:
parse_second(href)
break
def parse_second(url):
scraper = cloudscraper.create_scraper(
browser={
'browser': 'chrome',
'platform': 'android',
'desktop': False
}
)
response = scraper.get(url)
tree = etree.HTML(response.text)
url1 = tree.xpath("//script[@class='wp-playlist-script']/text()")[0]
date = json.loads(url1)
links = date["tracks"]
for link in links:
src = link['src1']
name = link['src0'].split('/')[-1]
parse_third(src, name)
break
# if scraper:
# scraper.close()
def parse_third(src, name):
url = f"https://ddys.pro/getvddr3/video?id={src}&type=json"
scraper = cloudscraper.create_scraper(
browser={
'browser': 'chrome',
'platform': 'android',
'desktop': False
}
)
response = scraper.get(url)
print(response.text)
# parsed_data = json.loads(response.text)
# url = parsed_data["url"]
# idmDownloader(url, name)
def idmDownloader(task_url, file_name):
"""
IDM下载器
:param task_url: 下载任务地址
:param folder_path: 存放文件夹
:param file_name: 文件名
:return:
"""
# IDM安装目录
IDM = "F:\\Internet Download Manager\\IDMan.exe"
# 下载地址
folder_path = 'C:\\Users\\mark\\Desktop\\dd'
# 将任务添加至队列
call(, '/d', task_url, '/p', folder_path, '/f', file_name, '/n', '/a'])
# 开始任务队列
call(, '/s'])
if __name__ == '__main__':
url = 'https://ddys.pro/'
parse(url)
页:
[1]