[英]python download files too slow
python give me 2.21s/MB which isn't the real speed of my internet, i don't know why.. python 给我 2.21s/MB 这不是我的互联网的真实速度,我不知道为什么..
this is the code i try to download without tqdm but that didn't work i try to download without stream = true and try with smaller file and it's donwloading with good speed but some time it's stop downloading这是我尝试在没有 tqdm 的情况下下载的代码,但没有成功
import requests
from bs4 import BeautifulSoup
from tqdm import tqdm
links = []
def download_from_anon(url):
global link, total_size, vid_link
req = requests.get(url)
soup = BeautifulSoup(req.text, "html.parser")
div = soup.find("div", { "id": "download-wrapper" })
link = div.findAll("a")[0]['href']
vid_link = requests.get(link, stream = True)
total_size = int(vid_link.headers['content-length'])
def get_the_links_from_gateanime(url):
global LINK4SH
tst = requests.get(url, headers=headers)
soup = BeautifulSoup(tst.content, "html.parser")
tbody = soup.find('tbody')
tr = tbody.findAll('tr')
for i in tr:
td = i.findAll('td')
span = td[2].find("span")
img = span.findAll("img")[0]['alt']
quality = td[4].find("span").text
if "4shared" in img:
get_the_link(td[1], quality)
elif " Anonfiles" in img:
get_the_link(td[1], quality)
print(links)
def get_the_link(tdList, qu):
if qu == "1080p" or qu == "720p":
LINK = tdList.find('a')['href']
links.append(LINK)
if '4shared' in links[0] and '1080FHD' in links[0]:
links.pop(0)
def main():
#for i in range(180, 221):
chunk_size = 1024*1024
url = "https://ww.gateanime.com/movie/%d9%81%d9%8a%d9%84%d9%85-kimetsu-no-yaiba-movie-mugen-ressha-hen-%d9%85%d8%aa%d8%b1%d8%ac%d9%85/"
get_the_links_from_gateanime(url)
download_from_anon(links[0])
with open(f"D:\igxs\spend time folder\\Kimetsu no Yaiba Movie: Mugen Ressha-hen.mp4", 'wb') as f:
for data in tqdm(iterable = vid_link.iter_content(chunk_size = chunk_size), total = int(total_size/chunk_size), unit = 'MB'):
f.write(data)
#-----------FUNCTION SECTION END-----------#
#-----------------------------------------------------#
#-----------WORK SECTION START-----------#
main()
i know it's really messy but that's it:)我知道这真的很乱,但就是这样:)
You can download a file as urrlib module as below:您可以下载文件作为 urrlib 模块,如下所示:
Firstly import urllib module首先导入 urllib 模块
import urllib.requests
Then use necessary method for download:然后使用必要的方法进行下载:
def download_from_anon(url):
global link, total_size, vid_link
req = requests.get(url)
soup = BeautifulSoup(req.text, "html.parser")
div = soup.find("div", { "id": "download-wrapper" })
link = div.findAll("a")[0]['href']
urllib.request.urlretrieve(link, file_name)
This method maybe can help you.这种方法也许可以帮助你。 Good luck:)
祝你好运:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.