<jupyter_start><jupyter_text>Scrape your growth mentor reviews and save to a CSV<jupyter_code># Install packages
!pip3 install requests
!pip3 install beautifulsoup4
# Import libraries
import requests
from bs4 import BeautifulSoup
from tqdm import tqdm
import pandas as pd
import datetime as dt
from google.colab import files
# Pull page data
URL = 'https://app.growthmentor.com/michael-taylor' #@param {type:"string"}
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')

review_rows = soup.find_all('div', class_='row mb-4')
print(f"Reviews: {len(review_rows)}")
print(review_rows[0].prettify())
# Get name
review_rows[0].div.div.text
# Get date
review_rows[0].div.contents[-1].text.strip()
# Get review
review_rows[0].p.text
# Get photo
review_rows[0].div.img['src']
# Scrape all reviews
reviews = list()
for row in tqdm(review_rows):
    review = dict()
    review['Name'] = row.div.div.text
    review['Date'] = row.div.contents[-1].text.strip()
    review['Review'] = row.p.text
    photo = row.div.img['src']
    if '/rails/active_storage/' in photo or '/assets/user_placeholder-' in photo:
        review['Photo'] = 'https://app.growthmentor.com' + photo
    else:
        review['Photo'] = photo

    reviews.append(review)

df = pd.DataFrame(reviews)
df.head()
# Reviews scraped
len(df)
# Save reviews to CSV
date = dt.datetime.now().strftime("%Y-%m-%d")
filename = f"growth_mentor_reviews_{date}.csv"
df.to_csv(filename, index=False)
files.download(filename)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14671052631578949, 'fraction_numerical': 0.007894736842105263, 'mean_word_length': 4.895348837209302, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '177285', 'license': 'MIT', 'n_tokens_mistral': 540, 'n_tokens_neox': 522, 'n_words': 124, 'path': 'scrape_gm_reviews.ipynb', 'repo_name': 'mjt145/scrape_gm_reviews', 'size': '1520'}