From dcdafe619fecea7b798dcfcc5cdb570c162f77af Mon Sep 17 00:00:00 2001 From: Anshika Yadav <14anshika7yadav@gmail.com> Date: Sat, 18 May 2024 10:37:09 +0530 Subject: [PATCH] fix: Feat: Scrapping data from Indiantrekking #904 --- documentation.md | 19 ++++++++ src/scrape_up/indiantrekking/__init__.py | 3 ++ src/scrape_up/indiantrekking/trek.py | 62 ++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 src/scrape_up/indiantrekking/__init__.py create mode 100644 src/scrape_up/indiantrekking/trek.py diff --git a/documentation.md b/documentation.md index 342172ac..468e9ebe 100644 --- a/documentation.md +++ b/documentation.md @@ -651,6 +651,25 @@ hc = healthgrades.HealthGrades() --- +### Indiantrekking + +```py +from scrape_up import Indiantrekking +``` + +Create an instance of 'Indiantrekking' class + +```python +trek=Indiantrekking("hidden-lakes-of-kashmir") +``` + + | Method | Details | + | --------------------------- | -------------------------------------------------------------------- | + |`destination()` | return name of the place. | + |`trip_fact()` | returns the trip duration, destination, altitude and the season good for trekking | + |`outline_day_to_day_itinerary` | returns the ouline of the day to day itinerary | + --- + ### IMDB ```py diff --git a/src/scrape_up/indiantrekking/__init__.py b/src/scrape_up/indiantrekking/__init__.py new file mode 100644 index 00000000..a9733576 --- /dev/null +++ b/src/scrape_up/indiantrekking/__init__.py @@ -0,0 +1,3 @@ +from .trek import Indiantrekking + +__all__ = ["Indiantrekking"] diff --git a/src/scrape_up/indiantrekking/trek.py b/src/scrape_up/indiantrekking/trek.py new file mode 100644 index 00000000..58cb3c99 --- /dev/null +++ b/src/scrape_up/indiantrekking/trek.py @@ -0,0 +1,62 @@ +from bs4 import BeautifulSoup +import re +import requests + + +class Indiantrekking: + """ + A class to scrape data from Indian trekking + + Create an instance of `Indiantrekking` class + + ```python + trek=Indiantrekking("hidden-lakes-of-kashmir") + ``` + + | Method | Details | + | --------------------------- | -------------------------------------------------------------------- | + |`destination()` | return name of the place. | + |'trip_fact()' | returns the trip duration, destination, altitude and the season good for trekking | + |'outline_day_to_day_itinerary' | returns the ouline of the day to day itinerary | + --- + """ + + def __init__(self, place): + self.place = place + try: + url = f"https://www.indiantrekking.com/{self.place}.html" + response = requests.get(url, headers={"User-Agent": "XY"}) + self.soup = BeautifulSoup(response.content, "lxml") + except: + return None + + def destination_name(self): + try: + place = self.soup.find("div", class_="main-title").text + return place + except: + return None + + def trip_fact(self): + try: + trip_duration = self.soup.findAll("div", class_="inner-wrap")[0].b.text + trip_destination = self.soup.findAll("div", class_="inner-wrap")[1].b.text + trip_season = self.soup.findAll("div", class_="inner-wrap")[3].b.text + trip_altitude = self.soup.findAll("div", class_="inner-wrap")[4].b.text + + tripfact = { + "trip_duration": re.sub(" +", " ", trip_duration.strip()), + "trip_destination": re.sub(" +", " ", trip_destination.strip()), + "trip_season": re.sub(" +", " ", trip_season.strip()), + "trip_altitude": re.sub(" +", " ", trip_altitude.strip()), + } + return tripfact + except: + return None + + def outline_day_to_day_itinerary(self): + try: + outline = self.soup.find("div", class_="itinerary").text + return outline + except: + return None