如何使用urllib.request获取文件的URL列表?


from urllib.request import urlopen
import re
urlpath =urlopen("http://blablabla.com/file")
string = urlpath.read().decode('utf-8')
pattern = re.compile('*.docx"')
onlyfiles = pattern.findall(string)
print(onlyfiles)

目标输出

['http://blablabla.com/file/1.docx','http://blablabla.com/file/2.docx']

但我有这个

[]

尝试此操作时收到此错误消息。

re.error: nothing to repeat at position 0

这一行的恒星:

pattern = re.compile('*.docx"')

显然是一个已知的蟒蛇错误:

查看以下相关答案:regex错误-无需重复

使用worda-zregexp:尝试此操作

pattern = re.compile('w*.docx"')
# or
pattern = re.compile('[a-zA-Z0-9]*.docx"')

最新更新