如何从网站下载Python文件?
我需要从下载所有英文子网站。文件链接必须是这样的:()。 这是我的代码:如何从网站下载Python文件?,python,download,Python,Download,我需要从下载所有英文子网站。文件链接必须是这样的:()。 这是我的代码: import requests import validators import sys from bs4 import BeautifulSoup as bs from urllib.parse import urlparse import wget from urllib.request import urlopen import urllib.request def check_validity(my_url):
import requests
import validators
import sys
from bs4 import BeautifulSoup as bs
from urllib.parse import urlparse
import wget
from urllib.request import urlopen
import urllib.request
def check_validity(my_url):
try:
urlopen(my_url)
print("Valid URL")
except IOError:
print ("Invalid URL")
sys.exit()
def get_srts(my_url):
links = []
html = urlopen(my_url).read()
html_page = bs(html, features="lxml")
og_url = html_page.find("meta", property="og:url")
base = urlparse(my_url)
print("base ,base")
for link in html_page.find_all('a'):
current_link = link.get('href')
if current_link.endswith('srt'):
if og_url:
print("currentLink",current_link)
links.append(og_url["content"] + current_link)
else:
links.append(base.scheme + "://" + base.netloc + current_link)
for link in links:
try:
wget.download(link)
except:
print(" \n \n Unable to Download A File \n")
print('\n')
def main():
#print("Enter Link: ")
my_url = 'https://www.opensubtitles.org/de/search/sublanguageid-eng/searchonlymovies-on'
check_validity(my_url)
get_srts(my_url)
main()
问题是,我的下载程序找不到任何下载链接。og_url也是空的。
因为文件链接没有结尾“srt或zip”,所以我试图省去这一行(如果当前的链接是'srt'):)。
也许你有一个想法或提示。这里有一个想法或提示:
好的,在HTML中为一个链接下载一些东西,点击你可以在链接标签中添加下载
<a href="https://link" download>
您可以搜索这些内容。这里有一个想法或提示:
好的,在HTML中为一个链接下载一些东西,点击你可以在链接标签中添加下载
<a href="https://link" download>
你也许可以搜索一下。html页面的
是什么样子的?这是您期望的网页内容吗?html\u页面
是什么样子的?这是你期待的网页内容吗?