Update app2.py
Browse files
app2.py
CHANGED
@@ -1309,18 +1309,21 @@ CITIES_BY_STATE = {
|
|
1309 |
def format_url_component(s):
|
1310 |
return s.lower().replace(' ', '-').replace(',', '').replace('&', 'and')
|
1311 |
|
1312 |
-
def search_lawyers(practice_area, state, city
|
1313 |
-
base_url = "https://www.
|
1314 |
params = {
|
1315 |
-
'
|
1316 |
-
'
|
1317 |
-
'state': state,
|
1318 |
-
'city': city or '',
|
1319 |
-
'page': 1
|
1320 |
}
|
1321 |
|
1322 |
headers = {
|
1323 |
-
'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'
|
|
|
|
|
|
|
|
|
|
|
|
|
1324 |
}
|
1325 |
|
1326 |
try:
|
@@ -1328,16 +1331,16 @@ def search_lawyers(practice_area, state, city=None):
|
|
1328 |
response.raise_for_status()
|
1329 |
soup = BeautifulSoup(response.content, 'html.parser')
|
1330 |
|
1331 |
-
lawyer_cards = soup.find_all('div', class_='
|
1332 |
|
1333 |
lawyers = []
|
1334 |
for card in lawyer_cards[:5]: # Limit to top 5 results
|
1335 |
-
name_elem = card.find('h3', class_='name')
|
1336 |
if name_elem:
|
1337 |
name = name_elem.text.strip()
|
1338 |
-
location = card.find('
|
1339 |
-
practice_areas = card.find('
|
1340 |
-
profile_url = "https://www.
|
1341 |
|
1342 |
lawyers.append({
|
1343 |
'name': name,
|
@@ -1351,24 +1354,6 @@ def search_lawyers(practice_area, state, city=None):
|
|
1351 |
st.error(f"Error fetching lawyer data: {e}")
|
1352 |
return []
|
1353 |
|
1354 |
-
def get_cities(state):
|
1355 |
-
formatted_state = format_url_component(state)
|
1356 |
-
url = f"https://lawyers.findlaw.com/{formatted_state}/"
|
1357 |
-
|
1358 |
-
headers = {
|
1359 |
-
'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'
|
1360 |
-
}
|
1361 |
-
|
1362 |
-
try:
|
1363 |
-
response = requests.get(url, headers=headers, timeout=10)
|
1364 |
-
response.raise_for_status()
|
1365 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
1366 |
-
city_links = soup.find_all('a', class_='city-link')
|
1367 |
-
return [city.text.strip() for city in city_links]
|
1368 |
-
except requests.RequestException as e:
|
1369 |
-
print(f"Error fetching cities: {e}")
|
1370 |
-
return []
|
1371 |
-
|
1372 |
def lawyer_finder_ui():
|
1373 |
st.title("Lawyer Search System")
|
1374 |
|
@@ -1378,26 +1363,17 @@ def lawyer_finder_ui():
|
|
1378 |
"Intellectual Property", "Personal Injury", "Real Estate Law", "Tax Law"
|
1379 |
]
|
1380 |
|
1381 |
-
states =
|
1382 |
-
"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado",
|
1383 |
-
"Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho",
|
1384 |
-
"Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana",
|
1385 |
-
"Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota",
|
1386 |
-
"Mississippi", "Missouri", "Montana", "Nebraska", "Nevada",
|
1387 |
-
"New Hampshire", "New Jersey", "New Mexico", "New York",
|
1388 |
-
"North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon",
|
1389 |
-
"Pennsylvania", "Rhode Island", "South Carolina", "South Dakota",
|
1390 |
-
"Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington",
|
1391 |
-
"West Virginia", "Wisconsin", "Wyoming"
|
1392 |
-
]
|
1393 |
|
1394 |
selected_practice_area = st.selectbox("Select a Practice Area:", practice_areas)
|
1395 |
selected_state = st.selectbox("Select a State:", states)
|
1396 |
-
|
|
|
|
|
1397 |
|
1398 |
if st.button("Search Lawyers"):
|
1399 |
with st.spinner("Searching for lawyers..."):
|
1400 |
-
results = search_lawyers(selected_practice_area, selected_state,
|
1401 |
|
1402 |
if results:
|
1403 |
st.success(f"Found {len(results)} lawyers matching your criteria.")
|
@@ -1408,6 +1384,7 @@ def lawyer_finder_ui():
|
|
1408 |
else:
|
1409 |
st.warning("No lawyers found matching your criteria. Try broadening your search.")
|
1410 |
|
|
|
1411 |
class LegalDataRetriever:
|
1412 |
def __init__(self):
|
1413 |
self.session = requests.Session()
|
|
|
1309 |
def format_url_component(s):
|
1310 |
return s.lower().replace(' ', '-').replace(',', '').replace('&', 'and')
|
1311 |
|
1312 |
+
def search_lawyers(practice_area, state, city):
|
1313 |
+
base_url = "https://www.avvo.com/search/lawyer_search"
|
1314 |
params = {
|
1315 |
+
'q': practice_area,
|
1316 |
+
'loc': f"{city}, {state}"
|
|
|
|
|
|
|
1317 |
}
|
1318 |
|
1319 |
headers = {
|
1320 |
+
'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',
|
1321 |
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
1322 |
+
'Accept-Language': 'en-US,en;q=0.5',
|
1323 |
+
'Referer': 'https://www.avvo.com/',
|
1324 |
+
'DNT': '1',
|
1325 |
+
'Connection': 'keep-alive',
|
1326 |
+
'Upgrade-Insecure-Requests': '1',
|
1327 |
}
|
1328 |
|
1329 |
try:
|
|
|
1331 |
response.raise_for_status()
|
1332 |
soup = BeautifulSoup(response.content, 'html.parser')
|
1333 |
|
1334 |
+
lawyer_cards = soup.find_all('div', class_='lawyer-search-result')
|
1335 |
|
1336 |
lawyers = []
|
1337 |
for card in lawyer_cards[:5]: # Limit to top 5 results
|
1338 |
+
name_elem = card.find('h3', class_='v-lawyer-card-name')
|
1339 |
if name_elem:
|
1340 |
name = name_elem.text.strip()
|
1341 |
+
location = card.find('div', class_='v-lawyer-card-location').text.strip()
|
1342 |
+
practice_areas = card.find('div', class_='v-lawyer-card-practice-areas').text.strip()
|
1343 |
+
profile_url = "https://www.avvo.com" + name_elem.find('a')['href']
|
1344 |
|
1345 |
lawyers.append({
|
1346 |
'name': name,
|
|
|
1354 |
st.error(f"Error fetching lawyer data: {e}")
|
1355 |
return []
|
1356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1357 |
def lawyer_finder_ui():
|
1358 |
st.title("Lawyer Search System")
|
1359 |
|
|
|
1363 |
"Intellectual Property", "Personal Injury", "Real Estate Law", "Tax Law"
|
1364 |
]
|
1365 |
|
1366 |
+
states = list(CITIES_BY_STATE.keys())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1367 |
|
1368 |
selected_practice_area = st.selectbox("Select a Practice Area:", practice_areas)
|
1369 |
selected_state = st.selectbox("Select a State:", states)
|
1370 |
+
|
1371 |
+
cities = CITIES_BY_STATE[selected_state]
|
1372 |
+
selected_city = st.selectbox("Select a City:", cities)
|
1373 |
|
1374 |
if st.button("Search Lawyers"):
|
1375 |
with st.spinner("Searching for lawyers..."):
|
1376 |
+
results = search_lawyers(selected_practice_area, selected_state, selected_city)
|
1377 |
|
1378 |
if results:
|
1379 |
st.success(f"Found {len(results)} lawyers matching your criteria.")
|
|
|
1384 |
else:
|
1385 |
st.warning("No lawyers found matching your criteria. Try broadening your search.")
|
1386 |
|
1387 |
+
|
1388 |
class LegalDataRetriever:
|
1389 |
def __init__(self):
|
1390 |
self.session = requests.Session()
|