- Home
- Course Detail
regularpython@gmail.com
You are now watching:
Python Strings / of Python String RealTime Examples
from beautifultable import BeautifulTable table = BeautifulTable() table.column_headers = ["Word Name", "Word Density"] import requests from bs4 import BeautifulSoup try: resp = requests.get("http://www.123telugu.com/reviews/baahubali2-telugu-movie-review.html") jsoup = BeautifulSoup(resp.content, "html.parser") jsoup = jsoup.find("div", attrs={"class":"main-content-post"}) text = jsoup.text.strip().lower() # print(text.upper()) # print(text.find("rajamouli")) # print(text.rfind("rajamouli")) # print(text.index("Rajamouli")) # print(text.rindex("Rajamoi")) # print(text.title()) # # # Use of split function and count getWords = set(text.split()) for word in getWords: wordCount = text.count(word) table.append_row([word,wordCount]) print(table) # Use of Title # getWords = set(text.split()) # wordDensity = [] # for word in getWords: # wordCount = text.count(word) # table.append_row([word.title(),wordCount]) # print(table) except Exception as e: print(e)