0
私はPythonには初めてです。私はサイトからPDFをダウンロードするためのコードを書こうとしました。約3000のファイルをダウンロードした後、HTTP.errorを取得しています。プログラムは、ファイルのダウンロードをスキップする必要があります。python反復にエラーがある場合は次の繰り返しに進みます
import requests,bs4,os,time,wget,sys
url = str(input("type the url:"))# type URL
res=requests.get(url) # get url in requests module
res.raise_for_status() # test whether the link
print("request raised")
pdf_links = bs4.BeautifulSoup(res.text,"html5lib") # read the webpage using HTML
print ("read website")
empty_list = []
i = 0
for link in pdf_links.findAll(title="PDF file that opens in a new window"):
i+=1
print(i)
get_url = link.get('href') # get all link addresses
com_url = str("http://ciconline.nic.in//rti/docs/"+str(get_url)) #combine link address with URL of website
empty_list.append(com_url)
print ("appended list")
for j in range(len(empty_list)):
while True:
try:
list_link = empty_list[j]
print ("downloading %d.%s"%(j,list_link))
wget.download(list_link,"D:\RTI\CIC-JAN-MAR-2016")
except:
print("Oops!",sys.exc_info()[0],"occured.")
print("started iteration %d"%j)
continue
break
うんの場合には、:)は、同じ答えをするちょうど約た合意しました。 – krizajb
ありがとう、それは働いた – ravi
素晴らしい、私はあなたを助けることができてうれしいです。 https://stackoverflow.com/help/someone-answers –