【发布时间】:2017-04-09 03:20:24
【问题描述】:
我正在尝试创建一个脚本来抓取网页并下载找到的任何图像文件。
我的第一个函数是读取网页并将其分配给变量的 wget 函数。 我的第二个函数是在网页 html 中搜索“ssrc=”的正则表达式,函数如下:
def find_image(text):
'''Find .gif, .jpg and .bmp files'''
documents = re.findall(r'\ssrc="([^"]+)"', text)
count = len(documents)
print "[+] Total number of file's found: %s" % count
return '\n'.join([str(x) for x in documents])
这个输出是这样的:
example.jpg
image.gif
http://www.webpage.com/example/file01.bmp
我正在尝试编写第三个函数,该函数使用 urllib.urlretrieve(url, filename) 下载这些文件,但我不知道该怎么做,主要是因为一些输出是绝对路径,而其他输出是相对路径。我也不确定如何同时下载所有这些并下载,而无需每次都指定名称和位置。
【问题讨论】:
-
不要用正则表达式解析 html stackoverflow.com/questions/1732348/…
标签: python html-parsing