Download all pdf files from a website using Python

Check out the following implementation. I’ve used requests module instead of urllib to do the download. Moreover, I’ve used .select() method instead of .find_all() to avoid using re. import os import requests from urllib.parse import urljoin from bs4 import BeautifulSoup url = “http://www.gatsby.ucl.ac.uk/teaching/courses/ml1-2016.html” #If there is no such folder, the script will create one automatically … Read more

Replace all characters that aren’t letters and numbers with a hyphen [duplicate]

This should do what you’re looking for: function clean($string) { $string = str_replace(‘ ‘, ‘-‘, $string); // Replaces all spaces with hyphens. return preg_replace(‘/[^A-Za-z0-9\-]/’, ”, $string); // Removes special chars. } Usage: echo clean(‘a|”bc!@£de^&$f g’); Will output: abcdef-g Edit: Hey, just a quick question, how can I prevent multiple hyphens from being next to each … Read more

Load image to a tableView from URL iphone sdk

You can use GCD to load images in background thread, like this: //get a dispatch queue dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); //this will start the image loading in bg dispatch_async(concurrentQueue, ^{ NSData *image = [[NSData alloc] initWithContentsOfURL:imageURL]; //this will set the image when loading is finished dispatch_async(dispatch_get_main_queue(), ^{ imageView.image = [UIImage imageWithData:image]; }); }); Hi. … Read more