Skip to content

Commit

Permalink
fix: Feat: Scrapping data from Indiantrekking Clueless-Community#904
Browse files Browse the repository at this point in the history
  • Loading branch information
Anshika14528 committed May 18, 2024
1 parent bb810bf commit dcdafe6
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
19 changes: 19 additions & 0 deletions documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/scrape_up/indiantrekking/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .trek import Indiantrekking

__all__ = ["Indiantrekking"]
62 changes: 62 additions & 0 deletions src/scrape_up/indiantrekking/trek.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dcdafe6

Please sign in to comment.