Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何下载RegEx语句-Python中的多个文件_Python_Regex_Download_Urllib2_Urllib - Fatal编程技术网

如何下载RegEx语句-Python中的多个文件

如何下载RegEx语句-Python中的多个文件,python,regex,download,urllib2,urllib,Python,Regex,Download,Urllib2,Urllib,所以我有一个RegEx语句可以从我的个人项目网站im scrapingpersonal prject下载文件,我想下载RegEx语句找到的文件 问题:如何使用urllib或urllib2实现这一点 我知道我可以从特定的URL下载一个文件,但下载在regex v中找到的图像是我的问题为什么不使用请求?我不会使用regex解析URL…我有点习惯使用regex语句-抱歉!您首先必须确保匹配的是http地址,但除此之外,可能会有所帮助。在v:loop中使用for url来迭代您的匹配项如何确保它们是ht

所以我有一个RegEx语句可以从我的个人项目网站im scrapingpersonal prject下载文件,我想下载RegEx语句找到的文件

问题:如何使用urllib或urllib2实现这一点


我知道我可以从特定的URL下载一个文件,但下载在regex v中找到的图像是我的问题

为什么不使用请求?我不会使用regex解析URL…我有点习惯使用regex语句-抱歉!您首先必须确保匹配的是http地址,但除此之外,可能会有所帮助。在v:loop中使用for url来迭代您的匹配项如何确保它们是http匹配项?
def GetImage():
    with open('TestPage.txt') as f:
        for line in f:
            v = re.findall(r'\w+\.jpg|\w+\.bmp|\w+.\gif', line)
            if v:
                os.system("wget v") # Could I replace this with urllib.retrieve(v)?
                #Code to download files found in v should go here.
                print v

def main():
    url = "http://testpage/~drc/drx/index.html"
    webpage = urllib2.urlopen(url)

    content = webpage.read()
    f = open('TestPage.txt', 'w')
    f.write(content)
    f.close()