hi this is the code
#!/usr/bin/env python3
import requests
from bs4 import BeautifulSoup
from urllib.parse import quote
def extract_geekbench_data(html):
soup = BeautifulSoup(html, 'html.parser')
systems = soup.find_all('div', class_='list-col-inner')
extracted_data = []
code Copy code
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
def fetch_and_extract_geekbench_data(query):
encoded_query = quote(query)
url = f'https://browser.geekbench.com/search?page=1&q={encoded_query}&utf8=%E2%9C%93 '
code Copy code
try:
response = requests.get(url)
if response.status_code != 200:
return "Failed to retrieve data from Geekbench.", 0
extracted_data = extract_geekbench_data(response.content)
number_of_pages = count_search_pages(response.content)
return extracted_data, number_of_pages
except Exception as e:
return f"An error occurred: {str(e)}", 0
Example usage:
search_query = input("Enter your search query: ")
data, pages = fetch_and_extract_geekbench_data(search_query)
print(f"Data: {data}, Total Pages: {pages}")
User input for the search query
search_query = input("Enter your search query: ")
Fetch and extract Geekbench data and count pages
data, pages = fetch_and_extract_geekbench_data(search_query)
Check if data is returned or an error message
if isinstance(data, str):
print(data)
else:
# Print the extracted data
for entry in data:
print(entry)
code Copy code
# Print the total number of pages
print(f"Total number of pages: {pages}")
and this is the result
Enter your search query: 155h
{'System Name': 'SAMSUNG ELECTRONICS CO., LTD. 960XGK', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2057', 'Multi-Core Score': '9187'}
{'System Name': 'SAMSUNG ELECTRONICS CO., LTD. 960XGK', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2049', 'Multi-Core Score': '9242'}
{'System Name': 'ASUSTeK COMPUTER INC. ASUS Zenbook 14 UX3405MA_UX3405MA', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2228', 'Multi-Core Score': '11694'}
{'System Name': 'SAMSUNG ELECTRONICS CO., LTD. 960XGK', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2035', 'Multi-Core Score': '9344'}
{'System Name': 'LENOVO 21KC0000CD', 'CPU Name': 'Intel Core Ultra 7 155H\n1400 MHz\n(16 cores)', 'Single-Core Score': '2179', 'Multi-Core Score': '11502'}
{'System Name': 'ASUSTeK COMPUTER INC. ASUS Zenbook 14 UX3405MA_UX3405MA', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2285', 'Multi-Core Score': '10549'}
{'System Name': 'ASUSTeK COMPUTER INC. ASUS Zenbook 14 UX3405MA_UX3405MA', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2278', 'Multi-Core Score': '11712'}
{'System Name': 'SAMSUNG ELECTRONICS CO., LTD. 960XGK', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2093', 'Multi-Core Score': '11475'}
{'System Name': 'HP HP Spectre x360 2-in-1 Laptop 14-eu0xxx', 'CPU Name': 'Intel Core Ultra 7 155H\n1400 MHz\n(16 cores)', 'Single-Core Score': '2372', 'Multi-Core Score': '12174'}
{'System Name': 'ASUSTeK COMPUTER INC. ASUS Zenbook 14 UX3405MA_UX3405MA', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '1126', 'Multi-Core Score': '11098'}
{'System Name': 'SAMSUNG ELECTRONICS CO., LTD. 960XGK', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2319', 'Multi-Core Score': '12096'}
{'System Name': 'ASUSTeK COMPUTER INC. ASUS Zenbook 14 UX3405MA_UX3405MA', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2171', 'Multi-Core Score': '8471'}
{'System Name': 'ASUSTeK COMPUTER INC. ASUS Zenbook 14 UX3405MA_UX3405MA', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2239', 'Multi-Core Score': '11939'}
{'System Name': 'ASUSTeK COMPUTER INC. ASUS Zenbook 14 UX3405MA_UX3405MA', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2427', 'Multi-Core Score': '9663'}
{'System Name': 'ASUSTeK COMPUTER INC. ASUS Zenbook 14 UX3405MA_UX3405MA', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2408', 'Multi-Core Score': '12631'}
{'System Name': 'ASUSTeK COMPUTER INC. ASUS Zenbook 14 UX3405MA_UX3405MA', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2404', 'Multi-Core Score': '12841'}
{'System Name': 'ASUSTeK COMPUTER INC. ASUS Zenbook 14 UX3405MA_UX3405MA', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2409', 'Multi-Core Score': '12819'}
{'System Name': 'ASUSTeK COMPUTER INC. ASUS Zenbook 14 UX3405MA_UX3405MA', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2409', 'Multi-Core Score': '12641'}
{'System Name': 'SAMSUNG ELECTRONICS CO., LTD. 960QGK', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2233', 'Multi-Core Score': '12609'}
{'System Name': 'SAMSUNG ELECTRONICS CO., LTD. 960QGK', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '1256', 'Multi-Core Score': '6057'}
{'System Name': 'SAMSUNG ELECTRONICS CO., LTD. 960QGK', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '1576', 'Multi-Core Score': '7543'}
{'System Name': 'SAMSUNG ELECTRONICS CO., LTD. 940XGK', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '1638', 'Multi-Core Score': '10115'}
{'System Name': 'ASUSTeK COMPUTER INC. ASUS Zenbook 14 UX3405MA_UX3405MA', 'CPU Name': 'Intel Core Ultra 7 155H\n3800 MHz\n(16 cores)', 'Single-Core Score': '2339', 'Multi-Core Score': '12126'}
{'System Name': 'LENOVO 21KC0000CD', 'CPU Name': 'Intel Core Ultra 7 155H\n1400 MHz\n(16 cores)', 'Single-Core Score': '2359', 'Multi-Core Score': '11694'}
{'System Name': 'LENOVO 21KC0000CD', 'CPU Name': 'Intel Core Ultra 7 155H\n1400 MHz\n(16 cores)', 'Single-Core Score': '2322', 'Multi-Core Score': '11667'}
Total number of pages: 14