Skip to main content

Posts

Showing posts from 2022

Lambda Function

A lambda function is a small and anonymous function. "Anonymous function is a function without a name". We can define this function using lambda keyword.

Title Operation Function : Making Title as Slug

Example >> INPUT : myStr = "Legal Counsel 3 - 8 yrs' PQE"  >>  CODE : import re def apply_operation(title): title = unicode(title.lower().strip()) // if not work so just remove unicode title = title.replace('&','') title = re.sub(r'(?s)\s+', r'-', title) title = re.sub(r"(?s)[^a-z-0-9]",r"-", title) title = re.sub(r'(?s)\-{2,}', r'-', title)           return title result = apply_operation(myStr) print(result) >>  OUTPUT : legal-counsel-3-8-yrs-pqe >>  Additional Note : Add the following code if you want to convert non-english to english characters  with "import unicodedata" module. unicodedata.normalize('NFKD', title).encode('ASCII', 'ignore')

String Replace using List method

Example >> INPUT : myStr  = " https://pythonsmallsoultions.blogspot.com/?lang=en&page=0&pageSize=10" myStr_list = myStr.split("&") myStr_list[1] = 'page='+str(1) myStr = "&".join( myStr_list ) >> OUTPUT : https://pythonsmallsoultions.blogspot.com/?lang=en&page1&pageSize=10

Useful User-Agent List

Here is the full list of User-Agents Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1064 Safari/532.5 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.94 Chrome/37.0.2062.94 Safari/537.36 Mozilla/5.0 (Windows NT 5.1)  Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) Mozilla/5.0 (compatible; Bingbot/2.0; +http://www.bing.com/bingbot.htm) Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)  Chrome/52.0.2743.116  Chrome/60.0.3112.113 Googlebot/2.1 Google Chrome curl/7.29.0 curl/7.37.1 curl/7.69.1 python-requests/2.26.0 Wget/1.21.1 Slackbot-LinkExpa