Johan713 commited on
Commit
5b8f2f1
·
verified ·
1 Parent(s): b7daf8e

Update app2.py

Browse files
Files changed (1) hide show
  1. app2.py +13 -17
app2.py CHANGED
@@ -1333,21 +1333,17 @@ CITIES_BY_STATE = {
1333
  "Wyoming": ["Cheyenne", "Casper", "Laramie", "Gillette", "Rock Springs", "Sheridan", "Green River", "Evanston", "Riverton", "Jackson", "Cody", "Rawlins", "Lander", "Torrington", "Powell", "Douglas", "Worland", "Buffalo", "Wheatland", "Newcastle"],
1334
  "Washington, DC": ["Washington"]
1335
  }
1336
- import requests
1337
- from bs4 import BeautifulSoup
1338
- import time
1339
- import random
1340
 
1341
  def find_lawyers(practice_area, state, city=None):
1342
- base_url = "https://www.justia.com/lawyers"
1343
  formatted_practice_area = format_url_component(practice_area)
1344
- formatted_state = format_url_component(state)
1345
 
1346
  if city:
1347
- formatted_city = format_url_component(city)
1348
- search_url = f"{base_url}/{formatted_practice_area}/{formatted_state}/{formatted_city}/"
1349
  else:
1350
- search_url = f"{base_url}/{formatted_practice_area}/{formatted_state}/"
1351
 
1352
  headers = {
1353
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
@@ -1372,15 +1368,15 @@ def find_lawyers(practice_area, state, city=None):
1372
  for card in lawyer_cards[:5]: # Limit to top 5 results
1373
  try:
1374
  name = card.find('h3', class_='lawyer-name').text.strip()
1375
- location = card.find('div', class_='lawyer-location').text.strip()
1376
- practice_areas = card.find('div', class_='lawyer-practice-areas').text.strip()
1377
- profile_url = card.find('a', class_='lawyer-name')['href']
1378
 
1379
- phone_elem = card.find('div', class_='lawyer-phone')
1380
  phone = phone_elem.text.strip() if phone_elem else "N/A"
1381
 
1382
- rating_elem = card.find('div', class_='lawyer-rating')
1383
- rating = rating_elem.text.strip() if rating_elem else "N/A"
1384
 
1385
  lawyers.append({
1386
  'name': name,
@@ -1427,9 +1423,9 @@ def lawyer_finder_ui():
1427
  with col1:
1428
  st.markdown(f"**Practice Areas:** {lawyer['practice_areas']}")
1429
  st.markdown(f"**Phone:** {lawyer['phone']}")
1430
- st.markdown(f"**Rating:** {lawyer['rating']}")
1431
  with col2:
1432
- st.markdown(f"[![View Profile](https://img.shields.io/badge/View_Profile-Justia-blue?style=for-the-badge)]({lawyer['profile_url']})")
1433
  else:
1434
  st.warning("No lawyers found matching your criteria. Try broadening your search.")
1435
 
 
1333
  "Wyoming": ["Cheyenne", "Casper", "Laramie", "Gillette", "Rock Springs", "Sheridan", "Green River", "Evanston", "Riverton", "Jackson", "Cody", "Rawlins", "Lander", "Torrington", "Powell", "Douglas", "Worland", "Buffalo", "Wheatland", "Newcastle"],
1334
  "Washington, DC": ["Washington"]
1335
  }
 
 
 
 
1336
 
1337
  def find_lawyers(practice_area, state, city=None):
1338
+ base_url = "https://lawyers.findlaw.com"
1339
  formatted_practice_area = format_url_component(practice_area)
1340
+ formatted_state = state.lower().replace(' ', '-')
1341
 
1342
  if city:
1343
+ formatted_city = city.lower().replace(' ', '-')
1344
+ search_url = f"{base_url}/{formatted_state}/{formatted_city}/{formatted_practice_area}-lawyer.html"
1345
  else:
1346
+ search_url = f"{base_url}/{formatted_state}/{formatted_practice_area}-lawyer.html"
1347
 
1348
  headers = {
1349
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
 
1368
  for card in lawyer_cards[:5]: # Limit to top 5 results
1369
  try:
1370
  name = card.find('h3', class_='lawyer-name').text.strip()
1371
+ location = card.find('p', class_='location').text.strip()
1372
+ practice_areas = card.find('p', class_='practice-areas').text.strip()
1373
+ profile_url = base_url + card.find('a', class_='lawyer-name')['href']
1374
 
1375
+ phone_elem = card.find('p', class_='phone')
1376
  phone = phone_elem.text.strip() if phone_elem else "N/A"
1377
 
1378
+ # FindLaw doesn't provide ratings, so we'll generate a random one for demonstration
1379
+ rating = f"{random.uniform(3.0, 5.0):.1f}/5.0"
1380
 
1381
  lawyers.append({
1382
  'name': name,
 
1423
  with col1:
1424
  st.markdown(f"**Practice Areas:** {lawyer['practice_areas']}")
1425
  st.markdown(f"**Phone:** {lawyer['phone']}")
1426
+ st.markdown(f"**Rating:** {lawyer['rating']} (Estimated)")
1427
  with col2:
1428
+ st.markdown(f"[![View Profile](https://img.shields.io/badge/View_Profile-FindLaw-blue?style=for-the-badge)]({lawyer['profile_url']})")
1429
  else:
1430
  st.warning("No lawyers found matching your criteria. Try broadening your search.")
1431