웹 페이지에서 파일을 다운로드하고 싶습니다. 그 웹 페이지는 단지 하나의 .zip 파일 만 가지고 있습니다. (다운로드하고자하는 것입니다.) .zip 파일을 클릭하면 다운로드가 시작되지만 URL은 변경되지 않습니다. URL은 여전히 양식 http://ldn2800:8080/id=2800로 남아 있습니다. http://example.com/1.zip
형태의 URL이 없다는 것을 고려하여 어떻게 이것을 파이썬을 사용하여 다운로드 할 수 있습니까?url이 변경되지 않을 때 python을 사용하여 파일을 다운로드하는 방법
또한 페이지 http://ldn2800:8080/id=2800으로 바로 이동하면 페이지가 .zip 파일로 열리고 클릭하지 않고 다운로드되지 않습니다. 어떻게 그것을 파이썬을 사용하여 다운로드합니까?
업데이트 : 그냥 원하는 위치에 압축을 생성하지만 지퍼를 열 수 없습니다와는 아무 상관이없는,
if (str(dict.get('id')) == winID):
#or str(dict.get('id')) == linuxID):
#if str(dict.get('number')) == buildNo:
buildTypeId = dict.get('id')
ID = dict.get('id')
downloadURL = "http://example:8080/viewType.html?buildId=26009&tab=artifacts&buildTypeId=" + ID
directory = BindingsDest + "\\" + buildNo
if not os.path.exists(directory):
os.makedirs(directory)
fileName = None
if buildTypeId == linuxID:
fileName = linuxLib + "-" + buildNo + ".zip"
elif buildTypeId == winID:
fileName = winLib + "-" + buildNo + ".zip"
if fileName is not None:
print(dict)
downloadFile(downloadURL, directory, fileName)
def downloadFile(downloadURL, directory, fileName, user=user, password=password):
if user is not None and password is not None:
request = requests.get(downloadURL, stream=True, auth=(user, password))
else:
request = requests.get(downloadURL, stream=True)
with open(directory + "\\" + fileName, 'wb') as handle:
for block in request.iter_content(1024):
if not block:
break
handle.write(block)
을하지만 : 지금은 이런 식으로하고 있어요. 다음과 같이 할 수 있습니까? 웹 페이지에서 파일 이름을 검색 한 다음 일치하는 패턴을 다운로드하는 것과 같습니까?
이 도움이됩니다. http://stackoverflow.com/questions/11002014/downloading-file-with-python-mechanize – bernie
python을 사용하여 요청을 실행 해 보았습니까? 무슨 일이야? –
@ MarcoAcierno 지금 내가하고있는 일을 보여주는 질문을 업데이트했습니다. – Arshad