Revision: 35411
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 7, 2010 22:39 by Keef
Initial Code
import re import mechanize from BeautifulSoup import BeautifulSoup from array import array import random import ctypes # setup br = mechanize.Browser() links = [] random.seed() br.set_handle_robots(False) br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] # grab the index page br.open("http://wallbase.net/random") # get a list of links for link in br.links(url_regex="wallbase.net/wallpaper/"): links.append(link.url) # grab a random link, also convert list item to string rndurl = str(random.sample(links, 1)).strip('[]\'') response = br.open(rndurl) soup = BeautifulSoup(response.read()) imgurl = soup.find("div", { "id" : "bigwall" }).findNext('img')['src'] response2 = br.open(imgurl) # save wallpaper file = open("wallpaper.jpg","wb") file.write(response2.get_data()) file.close() # set wallpaper SPI_SETDESKWALLPAPER = 20 MY_WALLPAPER = "wallpaper.jpg" ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, MY_WALLPAPER , 0)
Initial URL
Initial Description
This has been made for Windows but shouldn't be hard to convert for other OS's.
Initial Title
Grab a random wallpaper from wallbase.net
Initial Tags
windows
Initial Language
Python