Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # Name: download
- # Function: Copy the contents of a file from a given URL
- # to a local file.
- # Parameter: url - URL to the file, which should be donwloaded
- # Return: none
- # Remarks: none
- import urllib
- def download(url):
- webFile = urllib.urlopen(url)
- localFile = open(url.split('/')[-1], 'w')
- localFile.write(webFile.read())
- webFile.close()
- localFile.close()
- # Name: strstr
- # Function: Get string in string
- # Parameter: sourcestring - String in which should be searched
- # searchstring - String to search in sourcestring
- # offset - offset to start searching
- # Return: None if failure
- # String since found string
- # Remarks: none
- def strstr(sourcestring, searchstring, offset = 0):
- pos = sourcestring.find(searchstring, offset)
- if pos < 0:
- return None
- else:
- return sourcestring[pos:]
- # Name: StringBetween
- # Function: Get string between two strings
- # Parameter: sourcestring - String in which should be searched
- # beginstring - the first string to determine
- # endstring - the last string to determine
- # Return: None if failure
- # String between the two strings
- # Remarks: none
- def StringBetween(searchstring, beginstring, endstring):
- start = strstr(searchstring, beginstring)
- if start == None:
- return None
- start = start[len(beginstring):]
- pos = start.find(endstring)
- if pos < 0:
- return None
- else:
- return start[:pos]
Advertisement
Add Comment
Please, Sign In to add comment