python request下载word_如何用python从httpu下载msworddocx文件

如果在浏览器中点击以下网址,docx文件将被下载,我想用python自动下载。在

我试过下面这些from docx import Document

import requests

import json

from bs4 import BeautifulSoup

dwnurl = 'https://hudoc.echr.coe.int/app/conversion/docx/?library=ECHR&id=001-176931&filename=CASE%20OF%20NDIDI%20v.%20THE%20UNITED%20KINGDOM.docx&logEvent=False'

doc = requests.get(dwnurl)

print(doc.content) #printing the document like b'PK\x03\x04\x14\x00\x06\x00\x08\x00\x00\x00!\x00!\xfb\x16\x01\x16\x02\x00\x00\xec\x0c\x00\x00\x13\x00\xc4\x01[Content_Types].xml \xa2\xc0\

print(doc.raw) #printing the document like

document = Document(doc.content)

document.save('test.docx')

#on document.save i have facing these issues

Traceback (most recent call last):

File "scraping_hudoc.py", line 40, in

document = Document(doc.content)

File "C:\Users\204387\AppData\Local\Programs\Python\Python36-32\lib\site-packages\docx\api.py", line 25, in Document

document_part = Package.open(docx).main_document_part

File "C:\Users\204387\AppData\Local\Programs\Python\Python36-32\lib\site-packages\docx\opc\package.py", line 116, in open

pkg_reader = PackageReader.from_file(pkg_file)

File "C:\Users\204387\AppData\Local\Programs\Python\Python36-32\lib\site-packages\docx\opc\pkgreader.py", line 32, in from_file

phys_reader = PhysPkgReader(pkg_file)

File "C:\Users\204387\AppData\Local\Programs\Python\Python36-32\lib\site-packages\docx\opc\phys_pkg.py", line 101, in __init__

self._zipf = ZipFile(pkg_file, 'r')

File "C:\Users\204387\AppData\Local\Programs\Python\Python36-32\lib\zipfile.py", line 1108, in __init__

self._RealGetContents()

File "C:\Users\204387\AppData\Local\Programs\Python\Python36-32\lib\zipfile.py", line 1171, in _RealGetContents

endrec = _EndRecData(fp)

File "C:\Users\204387\AppData\Local\Programs\Python\Python36-32\lib\zipfile.py", line 241, in _EndRecData

fpin.seek(0, 2)

AttributeError: 'bytes' object has no attribute 'seek'

你可能感兴趣的:(python,request下载word)