for system in systems:
system_name_tag = system.find('a')
system_name = system_name_tag.get_text(strip=True) if system_name_tag else "Unknown"
cpu_name_tag = system.find('span', class_='list-col-model')
cpu_name = cpu_name_tag.get_text(strip=True) if cpu_name_tag else "Unknown CPU"
scores = system.find_all('span', class_='list-col-text-score')
if len(scores) >= 2:
single_core_score = scores[0].get_text(strip=True)
multi_core_score = scores[1].get_text(strip=True)
extracted_data.append({
'System Name': system_name,
'CPU Name': cpu_name,
'Single-Core Score': single_core_score,
'Multi-Core Score': multi_core_score
})
return extracted_data
def count_search_pages(html):
soup = BeautifulSoup(html, 'html.parser')
pagination_container = soup.find('ul', class_='pagination')
if pagination_container:
# Extracting all the page items
page_items = pagination_container.find_all('li', class_='page-item')
# Finding the last page number from the page item list
last_page_item = page_items[-2] if len(page_items) > 2 else None
last_page_number = int(last_page_item.find('a').text) if last_page_item else 0
return last_page_number
else:
return 0
This is a Python script that fetches and extracts data from Geekbench, a website that provides benchmarking scores for computer processors. The script uses the requests and BeautifulSoup libraries in Python to fetch the page containing the search results and extract the system names, CPU names, single-core scores, and multi-core scores for each system.
Here's a breakdown of the script:
The script starts by importing the necessary libraries: requests, BeautifulSoup, quote, and urllib.parse.
The fetch_and_extract_geekbench_data() function is defined. This function takes a query string as input and fetches the Geekbench search results page for that query.
The function extracts the system names, CPU names, single-core scores, and multi-core scores for each system in the search results page using BeautifulSoup.
The function returns a list of tuples, where each tuple contains the system name, CPU name, single-core score, and multi-core score for a particular system.
The script then defines a function named count_search_pages() that counts the number of pages in the Geekbench search results.
The script then calls the fetch_and_extract_geekbench_data() function with the input query provided by the user.
The script prints the extracted data and the total number of pages in the search results.
The script appears to be working correctly, as it lists the system names, CPU names, single-core scores, and multi-core scores for each system in the search results page. The total number of pages in the search results is also printed at the end.