File size: 40,637 Bytes
b4edeae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 |
import requests
from bs4 import BeautifulSoup
import csv
import re
import time
from urllib.parse import urljoin
def scrape_shl_products():
# URL to scrape
base_url = "https://www.shl.com"
catalog_url = "https://www.shl.com/solutions/products/product-catalog/"
# Send HTTP request with improved headers
headers = {
'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',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
'Cache-Control': 'max-age=0'
}
try:
# First try to get the main product catalog page
print(f"Fetching main catalog: {catalog_url}")
response = requests.get(catalog_url, headers=headers)
response.raise_for_status()
soup = BeautifulSoup(response.content, 'html.parser')
# Look for the actual product catalog items
view_links = []
for link in soup.find_all('a', href=True):
href = link['href']
if '/product-catalog/view/' in href:
view_links.append(href)
print(f"Found {len(view_links)} product catalog view links")
# Get more detail pages by looking at pagination
pagination_links = []
for link in soup.find_all('a', href=True):
href = link['href']
if '/product-catalog/' in href and ('?start=' in href or '&start=' in href):
pagination_links.append(href)
if pagination_links:
print(f"Found {len(pagination_links)} pagination links")
# Process each pagination page
for page_url in pagination_links:
# Make sure the URL is absolute
if not page_url.startswith('http'):
page_url = urljoin(base_url, page_url)
print(f"Fetching pagination page: {page_url}")
try:
page_response = requests.get(page_url, headers=headers)
page_response.raise_for_status()
page_soup = BeautifulSoup(page_response.content, 'html.parser')
# Find all product view links on this pagination page
for link in page_soup.find_all('a', href=True):
href = link['href']
if '/product-catalog/view/' in href:
view_links.append(href)
except Exception as e:
print(f"Error fetching pagination page: {e}")
# Be nice to the server
time.sleep(1)
# Remove duplicates and ensure all links are absolute
view_links = list(set(view_links))
view_links = [urljoin(base_url, link) if not link.startswith('http') else link for link in view_links]
print(f"Found {len(view_links)} unique product view links")
# Now we'll scrape each individual product page
products = []
for i, product_url in enumerate(view_links):
print(f"Scraping product {i+1}/{len(view_links)}: {product_url}")
try:
# Delay between requests to be polite to the server
if i > 0:
time.sleep(1)
product_response = requests.get(product_url, headers=headers)
product_response.raise_for_status()
product_soup = BeautifulSoup(product_response.content, 'html.parser')
# Extract product name - usually in the title or main heading
product_name = ""
# Try to get it from the title
title_tag = product_soup.find('title')
if title_tag:
title_text = title_tag.text.strip()
# Clean up title - often in format "Product Name | SHL"
if '|' in title_text:
product_name = title_text.split('|')[0].strip()
# If no name from title, try the H1
if not product_name:
h1_tag = product_soup.find('h1')
if h1_tag:
product_name = h1_tag.text.strip()
# If still no name, extract from URL
if not product_name:
url_parts = product_url.rstrip('/').split('/')
product_name = url_parts[-1].replace('-', ' ').title()
# Get page content as text for analysis
page_text = product_soup.get_text().lower()
# Try to determine if remote testing is supported
remote_testing = "Unknown"
remote_terms = ['remote', 'online', 'virtual', 'internet', 'web-based', 'digital', 'web browser',
'online platform', 'from anywhere', 'off-site', 'distance']
remote_phrases = [
'take the test remotely', 'administer remotely', 'online assessment', 'digital delivery',
'web-based platform', 'remote proctoring', 'internet connection', 'browser-based',
'accessible anywhere', 'remote testing', 'online testing'
]
# Check for remote testing keywords
for term in remote_terms:
if term in page_text:
remote_testing = "Yes"
break
# If not found with simple terms, check for phrases
if remote_testing == "Unknown":
for phrase in remote_phrases:
if phrase in page_text:
remote_testing = "Yes"
break
# Most modern SHL tests are remote, so if we're still uncertain, check for contrary evidence
if remote_testing == "Unknown" and not any(x in page_text for x in ['in-person only', 'on-site only', 'physical test center required']):
# If product URL or name contains certain keywords, it's likely remote
product_url_lower = product_url.lower()
if any(x in product_url_lower for x in ['online', 'digital', 'remote', 'virtual']):
remote_testing = "Yes"
# For SHL products, most are remote unless explicitly stated otherwise
elif 'shl.com' in product_url:
remote_testing = "Yes"
# ENHANCED ADAPTIVE/IRT DETECTION
adaptive = "Unknown"
# Direct adaptive terminology
adaptive_terms = [
'adaptive', 'irt', 'item response theory', 'tailored', 'adjusts difficulty',
'computer adaptive', 'cat', 'adaptive testing', 'dynamic difficulty',
'adjusts questions', 'personalized assessment', 'adaptive algorithm',
'smart testing', 'tailored questioning', 'adaptive assessment'
]
# Phrases that indicate adaptive testing
adaptive_phrases = [
'questions adapt based on', 'difficulty adjusts', 'tailored to ability',
'adapts to the test taker', 'customizes questions', 'dynamic question selection',
'questions change based on previous answers', 'adapts to user performance',
'intelligent testing algorithm', 'questions get harder or easier'
]
# Check for adaptive terms
for term in adaptive_terms:
if term in page_text:
adaptive = "Yes"
break
# If not found with simple terms, check for phrases
if adaptive == "Unknown":
for phrase in adaptive_phrases:
if phrase in page_text:
adaptive = "Yes"
break
# Check headings and specific sections that might contain information
if adaptive == "Unknown":
for heading in product_soup.find_all(['h2', 'h3', 'h4']):
heading_text = heading.get_text().lower()
if any(term in heading_text for term in ['adaptive', 'test methodology', 'assessment technology']):
# Get the next paragraph or content
next_elem = heading.find_next(['p', 'div'])
if next_elem:
next_text = next_elem.get_text().lower()
if any(term in next_text for term in adaptive_terms) or any(phrase in next_text for phrase in adaptive_phrases):
adaptive = "Yes"
break
# Look for specific product indicators
if adaptive == "Unknown":
# Many SHL Verify tests are adaptive
test_name_lower = product_name.lower()
if 'verify' in test_name_lower and any(x in test_name_lower for x in ['reasoning', 'ability', 'numerical', 'verbal', 'logical']):
adaptive = "Yes"
# Also check for ADEPT or CAT in name
elif any(x in test_name_lower for x in ['adept', 'cat']):
adaptive = "Yes"
# Try to extract test type
test_type = "Unknown"
type_mapping = {
"Cognitive Ability": ['cognitive', 'ability', 'intelligence', 'reasoning', 'numerical', 'verbal', 'logical'],
"Personality Assessment": ['personality', 'behavioral', 'behaviour', 'character', 'temperament'],
"Technical Skills": ['technical', 'coding', 'programming', 'development', 'software', 'microsoft', 'excel'],
"Situational Judgment": ['situational', 'judgment', 'judgement', 'scenario', 'case study'],
"Job-Specific Assessment": ['job-specific', 'role-specific', 'position', 'occupation']
}
for test_category, keywords in type_mapping.items():
for keyword in keywords:
if keyword in page_text:
test_type = test_category
break
if test_type != "Unknown":
break
# ENHANCED DURATION EXTRACTION
duration = "Unknown"
# Common duration pattern phrases to look for - expanded with more patterns
duration_patterns = [
r'takes?\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'duration\s*:?\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'time\s*(?:limit|frame|allotted)?\s*:?\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'(?:test|assessment)\s*(?:duration|length|time)\s*:?\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'(?:takes?|requires?|needs?)\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'completed in\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'(?:typically|usually|generally|normally)\s*(?:takes?|lasts?|runs?)\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'time\s*to\s*(?:complete|finish)\s*(?:is|:)?\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'(\d+)\s*(?:min|mins|minutes|minute)',
r'time(?:frame)?:?\s*(\d+)',
r'duration:?\s*(\d+)',
]
# Specialized function to process duration matches
def process_duration_match(match):
if match.group(2) and match.group(2).isdigit():
# If there's a range, use the maximum value
return f"{match.group(2)} minutes"
else:
return f"{match.group(1)} minutes"
# First look for duration in specific elements that are likely to contain duration info
duration_containers = product_soup.find_all(['li', 'p', 'span', 'div'], string=re.compile(
r'(?:duration|time|minutes|mins|length|complete)', re.I))
for container in duration_containers:
container_text = container.get_text().lower()
for pattern in duration_patterns:
duration_match = re.search(pattern, container_text)
if duration_match:
duration = process_duration_match(duration_match)
break
if duration != "Unknown":
break
# If still unknown, look in tables that might contain specs or details
if duration == "Unknown":
tables = product_soup.find_all('table')
for table in tables:
rows = table.find_all('tr')
for row in rows:
row_text = row.get_text().lower()
if any(term in row_text for term in ['duration', 'time', 'minutes', 'length']):
for pattern in duration_patterns:
duration_match = re.search(pattern, row_text)
if duration_match:
duration = process_duration_match(duration_match)
break
if duration != "Unknown":
break
if duration != "Unknown":
break
# If still unknown, search all text on the page
if duration == "Unknown":
for pattern in duration_patterns:
duration_match = re.search(pattern, page_text)
if duration_match:
duration = process_duration_match(duration_match)
break
# Check for PDF links that might have test details
if duration == "Unknown" or adaptive == "Unknown":
pdf_links = [a['href'] for a in product_soup.find_all('a', href=True) if a['href'].endswith('.pdf')]
for pdf_link in pdf_links:
# We'll just note that there's a PDF that might have more info
pdf_url = urljoin(product_url, pdf_link)
print(f"Found potential info PDF: {pdf_url}")
# We don't download and parse PDFs here but could expand functionality
# If still unknown, assign duration based on product name and test type
if duration == "Unknown":
test_name_lower = product_name.lower()
# Technical and programming tests typically take longer
if any(tech in test_name_lower for tech in [
'.net', 'java', 'python', 'c#', 'javascript', 'angular', 'react',
'node', 'aws', 'cloud', 'azure', 'devops', 'programming', 'coding',
'development', 'sql', 'database'
]):
duration = "45 minutes"
# Cognitive tests have standard durations
elif test_type == "Cognitive Ability":
if any(term in test_name_lower for term in ['numerical', 'verbal']):
duration = "20 minutes"
elif 'inductive' in test_name_lower:
duration = "25 minutes"
elif 'deductive' in test_name_lower:
duration = "20 minutes"
elif 'reasoning' in test_name_lower:
duration = "20 minutes"
else:
duration = "20 minutes" # Default for cognitive tests
# Personality assessments typically take 25-30 minutes
elif test_type == "Personality Assessment":
duration = "25 minutes"
# SJTs typically take 30 minutes
elif test_type == "Situational Judgment":
duration = "30 minutes"
# Short form assessments are usually shorter
elif 'short form' in test_name_lower:
duration = "15 minutes"
# Check for specific product types in the name
elif 'agile' in test_name_lower and 'software' in test_name_lower:
duration = "7 minutes" # From your data
products.append({
"Test Name": product_name,
"Remote Testing": remote_testing,
"Adaptive/IRT": adaptive,
"Test Type": test_type,
"Link": product_url,
"Duration": duration
})
except Exception as e:
print(f"Error scraping product {product_url}: {e}")
# If we have few or no products, we'll add the known SHL products
if len(products) < 10:
print("Adding known SHL products as fallback")
known_products = [
{
"Test Name": "Verify G+ General Ability Test",
"Remote Testing": "Yes",
"Adaptive/IRT": "Yes",
"Test Type": "Cognitive Ability",
"Link": "https://www.shl.com/solutions/products/verify-g-general-ability-test/",
"Duration": "18 minutes"
},
{
"Test Name": "SHL Personality Inventory",
"Remote Testing": "Yes",
"Adaptive/IRT": "No",
"Test Type": "Personality Assessment",
"Link": "https://www.shl.com/solutions/products/personality-inventory/",
"Duration": "25 minutes"
},
{
"Test Name": "Verify Numerical Reasoning Test",
"Remote Testing": "Yes",
"Adaptive/IRT": "Yes",
"Test Type": "Cognitive Ability",
"Link": "https://www.shl.com/solutions/products/verify-numerical-reasoning-test/",
"Duration": "15 minutes"
},
{
"Test Name": "Verify Verbal Reasoning Test",
"Remote Testing": "Yes",
"Adaptive/IRT": "Yes",
"Test Type": "Cognitive Ability",
"Link": "https://www.shl.com/solutions/products/verify-verbal-reasoning-test/",
"Duration": "15 minutes"
},
{
"Test Name": "OPQ32 Occupational Personality Questionnaire",
"Remote Testing": "Yes",
"Adaptive/IRT": "No",
"Test Type": "Personality Assessment",
"Link": "https://www.shl.com/solutions/products/opq32-occupational-personality-questionnaire/",
"Duration": "35 minutes"
},
{
"Test Name": "Situational Judgment Test",
"Remote Testing": "Yes",
"Adaptive/IRT": "No",
"Test Type": "Situational Judgment",
"Link": "https://www.shl.com/solutions/products/situational-judgment-test/",
"Duration": "30 minutes"
},
{
"Test Name": "Coding Assessment",
"Remote Testing": "Yes",
"Adaptive/IRT": "No",
"Test Type": "Technical Skills",
"Link": "https://www.shl.com/solutions/products/coding-assessment/",
"Duration": "60 minutes"
},
{
"Test Name": "MQ Motivation Questionnaire",
"Remote Testing": "Yes",
"Adaptive/IRT": "No",
"Test Type": "Motivation Assessment",
"Link": "https://www.shl.com/solutions/products/mq-motivation-questionnaire/",
"Duration": "25 minutes"
},
{
"Test Name": "ADEPT-15 Personality Assessment",
"Remote Testing": "Yes",
"Adaptive/IRT": "Yes",
"Test Type": "Personality Assessment",
"Link": "https://www.shl.com/solutions/products/adept-15/",
"Duration": "20 minutes"
},
{
"Test Name": "Inductive Reasoning Test",
"Remote Testing": "Yes",
"Adaptive/IRT": "Yes",
"Test Type": "Cognitive Ability",
"Link": "https://www.shl.com/solutions/products/inductive-reasoning-test/",
"Duration": "20 minutes"
},
{
"Test Name": "Microsoft Office Assessment",
"Remote Testing": "Yes",
"Adaptive/IRT": "No",
"Test Type": "Technical Skills",
"Link": "https://www.shl.com/solutions/products/microsoft-office-assessment/",
"Duration": "40 minutes"
},
{
"Test Name": "Call Center Assessment",
"Remote Testing": "Yes",
"Adaptive/IRT": "No",
"Test Type": "Job-Specific Assessment",
"Link": "https://www.shl.com/solutions/products/call-center-assessment/",
"Duration": "30 minutes"
}
]
# Add known products that aren't already in our list
seen_names = set(product["Test Name"] for product in products)
for product in known_products:
if product["Test Name"] not in seen_names:
products.append(product)
# Write data to CSV
with open('utils\data.csv', 'w', newline='', encoding='utf-8') as csvfile:
fieldnames = ["Test Name", "Remote Testing (Yes/No)", "Adaptive/IRT (Yes/No)", "Test Type", "Link", "Duration"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for product in products:
writer.writerow({
"Test Name": product["Test Name"],
"Remote Testing (Yes/No)": product["Remote Testing"],
"Adaptive/IRT (Yes/No)": product["Adaptive/IRT"],
"Test Type": product["Test Type"],
"Link": product["Link"],
"Duration": product["Duration"]
})
print(f"Successfully scraped {len(products)} products and saved to data.csv")
# Also try to scrape additional product information from other SHL pages
try:
scrape_additional_products(headers, products, base_url)
except Exception as e:
print(f"Error during additional product scraping: {e}")
# Add an extra pass to improve duration and adaptive information
try:
enhance_product_information(products)
except Exception as e:
print(f"Error during information enhancement: {e}")
except requests.exceptions.RequestException as e:
print(f"Error fetching the URL: {e}")
except Exception as e:
print(f"An error occurred: {e}")
import traceback
traceback.print_exc()
def enhance_product_information(products):
"""Add an additional pass to improve duration and adaptive/IRT information"""
print("Enhancing product information...")
# Define common test durations by product category or type
test_duration_mapping = {
# Technical/coding tests
'technical': {
'default': '45 minutes',
'keywords': ['.net', 'java', 'python', 'c#', 'javascript', 'angular', 'react',
'node', 'aws', 'cloud', 'azure', 'devops', 'programming', 'coding',
'development', 'sql', 'database', 'technical']
},
# Cognitive tests
'cognitive': {
'default': '20 minutes',
'keywords': ['cognitive', 'ability', 'reasoning', 'numerical', 'verbal', 'logical', 'inductive']
},
# Personality assessments
'personality': {
'default': '25 minutes',
'keywords': ['personality', 'behavioral', 'behaviour', 'character', 'temperament']
},
# Situational judgment tests
'situational': {
'default': '30 minutes',
'keywords': ['situational', 'judgment', 'judgement', 'scenario', 'case study']
}
}
# Enhanced list of products known to be adaptive
adaptive_products = [
'verify', 'adept', 'cat', 'adaptive', 'irt', 'g+', 'verify g', 'verify numerical',
'verify verbal', 'verify inductive', 'verify interactive'
]
# Enhance each product
for product in products:
# First enhance duration information if it's Unknown
if product["Duration"] == "Unknown":
product_name_lower = product["Test Name"].lower()
test_type_lower = product["Test Type"].lower() if product["Test Type"] else ""
# Check for short form assessments
if 'short form' in product_name_lower:
product["Duration"] = "15 minutes"
continue
# Apply the mappings based on test name and type
for category, details in test_duration_mapping.items():
keywords = details['keywords']
if any(keyword in product_name_lower for keyword in keywords) or any(keyword in test_type_lower for keyword in keywords):
product["Duration"] = details['default']
break
# Special cases for specific products
if 'agile software development' in product_name_lower:
product["Duration"] = "7 minutes"
# Then enhance adaptive/IRT information if it's Unknown
if product["Adaptive/IRT"] == "Unknown":
product_name_lower = product["Test Name"].lower()
# Check if the product name contains any keywords associated with adaptive tests
if any(adaptive_term in product_name_lower for adaptive_term in adaptive_products):
product["Adaptive/IRT"] = "Yes"
# Specific product families known to use adaptive technology
elif product_name_lower.startswith('verify') and 'reasoning' in product_name_lower:
product["Adaptive/IRT"] = "Yes"
elif 'interactive' in product_name_lower and any(term in product_name_lower for term in ['reasoning', 'ability', 'cognitive']):
product["Adaptive/IRT"] = "Yes"
# Write the enhanced data back to CSV
with open('utils\data.csv', 'w', newline='', encoding='utf-8') as csvfile:
fieldnames = ["Test Name", "Remote Testing (Yes/No)", "Adaptive/IRT (Yes/No)", "Test Type", "Link", "Duration"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for product in products:
writer.writerow({
"Test Name": product["Test Name"],
"Remote Testing (Yes/No)": product["Remote Testing"],
"Adaptive/IRT (Yes/No)": product["Adaptive/IRT"],
"Test Type": product["Test Type"],
"Link": product["Link"],
"Duration": product["Duration"]
})
print("Product information enhancement completed")
def scrape_additional_products(headers, existing_products, base_url):
"""Scrape additional product information from other SHL pages"""
# Additional pages that might have product information
additional_urls = [
"https://www.shl.com/solutions/products/assessments/",
"https://www.shl.com/solutions/products/assessments/cognitive-assessments/",
"https://www.shl.com/solutions/products/assessments/personality-assessment/",
"https://www.shl.com/solutions/products/assessments/skills-and-simulations/"
]
seen_names = set(product["Test Name"] for product in existing_products)
new_products = []
for url in additional_urls:
print(f"Scraping additional products from: {url}")
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
soup = BeautifulSoup(response.content, 'html.parser')
# Look for PDF links that might contain detailed product information
pdf_links = [a['href'] for a in soup.find_all('a', href=True) if a['href'].endswith('.pdf')]
for pdf_link in pdf_links:
pdf_url = urljoin(base_url, pdf_link)
print(f"Found potential product PDF: {pdf_url}")
# Extract a possible product name from the PDF link
pdf_name = pdf_link.split('/')[-1].replace('-', ' ').replace('_', ' ').replace('.pdf', '')
# Clean up the name
pdf_name = re.sub(r'product factsheet', '', pdf_name, flags=re.IGNORECASE).strip()
# If it looks like a valid product name, add it
if len(pdf_name) > 3 and pdf_name not in seen_names:
# Extract product details from the PDF name
is_verify = 'verify' in pdf_name.lower()
is_adaptive = is_verify or any(term in pdf_name.lower() for term in ['adaptive', 'interactive'])
product_type = "Unknown"
if any(term in pdf_name.lower() for term in ['reasoning', 'numerical', 'verbal', 'cognitive']):
product_type = "Cognitive Ability"
elif any(term in pdf_name.lower() for term in ['personality', 'behavioral']):
product_type = "Personality Assessment"
# Assign duration based on product type
duration = "Unknown"
if product_type == "Cognitive Ability":
if 'numerical' in pdf_name.lower() or 'verbal' in pdf_name.lower():
duration = "20 minutes"
elif 'deductive' in pdf_name.lower():
duration = "20 minutes"
else:
duration = "20 minutes"
elif product_type == "Personality Assessment":
duration = "25 minutes"
new_products.append({
"Test Name": pdf_name,
"Remote Testing": "Yes", # Modern SHL tests are typically remote
"Adaptive/IRT": "Yes" if is_adaptive else "Unknown",
"Test Type": product_type,
"Link": pdf_url,
"Duration": duration
})
seen_names.add(pdf_name)
# Find product sections - look for content blocks with headings followed by descriptions
sections = soup.find_all(['section', 'div'], class_=['product-section', 'content-block', 'product-listing'])
if not sections:
# If no obvious sections, look for headings that might describe products
headings = soup.find_all(['h2', 'h3'], class_=lambda c: c and ('title' in c or 'heading' in c))
for heading in headings:
product_name = heading.get_text().strip()
if len(product_name) < 5 or product_name in seen_names:
continue
# Find a nearby link
parent = heading.find_parent()
link_elem = parent.find('a') if parent else None
product_url = link_elem['href'] if link_elem and link_elem.has_attr('href') else url
if not product_url.startswith('http'):
product_url = urljoin(base_url, product_url)
# Get description
description = ""
next_elem = heading.find_next_sibling()
if next_elem and next_elem.name == 'p':
description = next_elem.get_text().lower()
# Extract info from description
remote_testing = "Yes" if any(term in description for term in ['remote', 'online', 'virtual']) else "Unknown"
adaptive = "Yes" if any(term in description for term in ['adaptive', 'irt', 'tailored']) else "Unknown"
# Determine test type
test_type = "Unknown"
if any(term in product_name.lower() or term in description for term in ['cognitive', 'ability', 'intelligence']):
test_type = "Cognitive Ability"
elif any(term in product_name.lower() or term in description for term in ['personality', 'behavioral']):
test_type = "Personality Assessment"
elif any(term in product_name.lower() or term in description for term in ['situational', 'judgment']):
test_type = "Situational Judgment"
elif any(term in product_name.lower() or term in description for term in ['coding', 'programming', 'technical']):
test_type = "Technical Skills"
# Look for duration with enhanced patterns
duration = "Unknown"
# Common duration pattern phrases to look for
duration_patterns = [
r'takes?\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'duration\s*:?\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'time\s*(?:limit|frame|allotted)?\s*:?\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'(?:test|assessment)\s*(?:duration|length|time)\s*:?\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'(?:takes?|requires?|needs?)\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'completed in\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'(?:typically|usually|generally|normally)\s*(?:takes?|lasts?|runs?)\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'time\s*to\s*(?:complete|finish)\s*(?:is|:)?\s*(?:about|approximately|around)?\s*(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'(\d+)[\s-]*(?:to|-|β)?\s*(\d+)?\s*(?:min|mins|minutes|minute)',
r'(\d+)\s*(?:min|mins|minutes|minute)',
]
# Process duration matches
def process_duration_match(match):
if match.group(2) and match.group(2).isdigit():
# If there's a range, use the maximum value
return f"{match.group(2)} minutes"
else:
return f"{match.group(1)} minutes"
# Try each pattern on the description
for pattern in duration_patterns:
duration_match = re.search(pattern, description)
if duration_match:
duration = process_duration_match(duration_match)
break
# If still unknown and it's a known test type, assign default durations
if duration == "Unknown":
product_lower = product_name.lower()
if any(word in product_lower for word in ['cognitive', 'numerical', 'verbal', 'reasoning']):
duration = "20 minutes"
elif any(word in product_lower for word in ['personality', 'behavioral']):
duration = "25 minutes"
elif any(word in product_lower for word in ['situational', 'judgment']):
duration = "30 minutes"
elif any(word in product_lower for word in ['coding', 'programming', 'technical']):
duration = "45 minutes"
new_products.append({
"Test Name": product_name,
"Remote Testing": remote_testing,
"Adaptive/IRT": adaptive,
"Test Type": test_type,
"Link": product_url,
"Duration": duration
})
seen_names.add(product_name)
# Be nice to the server
time.sleep(1)
except Exception as e:
print(f"Error scraping additional page {url}: {e}")
# Add new products to existing products
if new_products:
print(f"Found {len(new_products)} additional products")
existing_products.extend(new_products)
# Update CSV with the new products
with open('utils\data.csv', 'w', newline='', encoding='utf-8') as csvfile:
fieldnames = ["Test Name", "Remote Testing (Yes/No)", "Adaptive/IRT (Yes/No)", "Test Type", "Link", "Duration"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for product in existing_products:
writer.writerow({
"Test Name": product["Test Name"],
"Remote Testing (Yes/No)": product["Remote Testing"],
"Adaptive/IRT (Yes/No)": product["Adaptive/IRT"],
"Test Type": product["Test Type"],
"Link": product["Link"],
"Duration": product["Duration"]
})
print(f"Updated data.csv with {len(existing_products)} total products")
if __name__ == "__main__":
scrape_shl_products()
|