diff --git a/BinancePriceScrapper.py b/BinancePriceScrapper.py new file mode 100644 index 0000000..7ef7087 --- /dev/null +++ b/BinancePriceScrapper.py @@ -0,0 +1,16 @@ +import requests, json + +BINANCE_ENDPOINT="https://www.binance.com/bapi/composite/v1/public/marketing/symbol/list" + +response = requests.get(BINANCE_ENDPOINT) + +i=0 +if response.status_code==200: + for asset in json.loads(response.text).get("data"): + print(i,end=")") + i=i+1 + print("NAME: {}\nSYMBOL: {}\nPRICE: {}\nTOTAL-SUPPLY: {}\n24HRS-PRICE-CHANGE: {}\n24HRS-PERCENT-CHANGE: {}" + .format(asset.get("name"), asset.get("symbol"), asset.get("price"), asset.get("totalSupply"), asset.get("dayChange"), asset.get("dayChangeAmount")), end="\n"+"="*100+"\n") + +else: + print("Oop! something went wrong status code: ", response.status_code) diff --git a/README.md b/README.md index a8f139d..07c9a68 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ # Web-Scraping -Web Scrapping examples using Beautiful Soup and Requests +Web Scrapping examples using Beautiful Soup and Requests. + +Beautiful Soup is a Python library designed for quick turnaround projects like screen-scraping. + +Prerequisites: + +* [Python 3.6+](https://www.python.org/downloads/) + +* [pip](https://pypi.org/project/pip/) + +* [Beautiful Soup 4](https://www.crummy.com/software/BeautifulSoup/) + +* [requests](https://pypi.org/project/requests/) + +* [rich](https://rich.readthedocs.io/en/stable/introduction.html)[for updatedcryptoprice.py] diff --git a/distro_ranking.py b/distro_ranking.py new file mode 100644 index 0000000..105185d --- /dev/null +++ b/distro_ranking.py @@ -0,0 +1,24 @@ +""" +REPO: https://github.com/ritik047/Web-Scraping +DATE: 2022-10-03 +USAGE: Python script for getting the top Linux distros in the last 30 days. +It queries https://distrowatch.com/dwres.php?resource=popularity to get the data. +""" + +# Define imports +from bs4 import BeautifulSoup +import requests + + +# Get the data +r = requests.get("https://distrowatch.com/dwres.php?resource=popularity", timeout=10) +soup = BeautifulSoup(r.content, 'html.parser') +vals = soup.find_all('td', class_="phr2") + +# As BeautifulSoup will return all the distros from all categories, +# we need to select the last 264 values in the last column +last_12_months = vals[792:1056] + +# Print out the data, in order, with it's ranking and name. +for c,v in enumerate(last_12_months): + print(f"{c+1}: {v.text}") diff --git a/updatedcryptoprice.py b/updatedcryptoprice.py new file mode 100644 index 0000000..06c9006 --- /dev/null +++ b/updatedcryptoprice.py @@ -0,0 +1,31 @@ +from bs4 import BeautifulSoup +import requests +from rich.console import Console +from rich.table import Table + +table = Table(title="Coin's Price") + +table.add_column("S. No.", style="cyan", no_wrap=True) +table.add_column("Coin Name", style="magenta") +table.add_column("Price", justify="left", style="green") + +url="https://coinmarketcap.com/" +result=requests.get(url).text +doc=BeautifulSoup(result,"html.parser") + +tbody=doc.tbody +trs=tbody.contents + + +prices=() + +for tr in trs[:10]: +for i,tr in enumerate(trs[:10]): + name,price=tr.contents[2:4] + print(name.p.string) + print(price.a.string) + + table.add_row(str(i+1),name.text,price.text) + +console = Console() +console.print(table)