Featured Post

Scraping Website: How to Write a Script in Python

Image
Here's a python script that you can use as a model to scrape a website. Python script The below logic uses BeautifulSoup Package for web scraping. import requests from bs4 import BeautifulSoup url = 'https://www.example.com' response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') # Print the title of the webpage print(soup.title.text) # Print all the links in the webpage for link in soup.find_all('a'):     print(link.get('href')) In this script, we first import the Requests and Beautiful Soup libraries. We then define the URL we want to scrape and use the Requests library to send a GET request to that URL. We then pass the response text to Beautiful Soup to parse the HTML contents of the webpage. We then use Beautiful Soup to extract the title of the webpage and print it to the console. We also use a for loop to find all the links in the webpage and print their href attributes to the console. This is just a basic example, but

Exploring Python's Comparison Operators: From == to <=

Here are the top comparison operators to compare numeric values in Python. Each operator explained with an example.

Python Comparison operators

List of operators

<
<=
>
>=
==
!=
Is
is not



How to use comparison operators

Here, I have assigned 23 to a and 11 to b. Then, I did apply all the comparison operators. The output is self-explanatory, and If you are in doubt while programming, remember to visit this page.


Operartors



Examples

a = 23
b = 11
print("Is a greater than b?", a > b)           #greater than
print("Is a less than b?", a < b)              #less than
print("Is a greater or equal to b?", a >= b)   #greater or equal
print("Is a less or equal to b?", a <= b)      #less or equal
print("Is a equal to b (option 1)?", a == b)         #test for equality
print("Is a equal to b (option 2)?", a is b)         #test for equality
print("Is a not equal to b (option 1)?", a != b)     #test for inequality
print("Is a not equal to b (option 2)?", a is not b) #test for inequality


The output

Is a greater than b? True
Is a less than b? False
Is a greater or equal to b? True
Is a less or equal to b? False
Is a equal to b (option 1)? False
Is a equal to b (option 2)? False
Is a not equal to b (option 1)? True
Is a not equal to b (option 2)? True


** Process exited - Return Code: 0 **
Press Enter to exit terminal

Related

Comments

Popular posts from this blog

7 AWS Interview Questions asked in Infosys, TCS

How to Decode TLV Quickly