-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (57 loc) · 2 KB
/
main.py
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
import time
import json
import math
from random import random
import selenium.webdriver
from selenium import webdriver
from selenium.webdriver.common.by import By
if __name__ == '__main__':
with open('cpu.jsonl', 'r') as file:
lines = file.readlines()
with open('cpu2.jsonl', 'r') as file:
for count, line in enumerate(file):
pass
cpu_list = []
c = 0
# Loop through each line and process it
driver = webdriver.Chrome()
driver.get("https://www.techpowerup.com/cpu-specs/")
time.sleep(5)
for line in lines:
c = c + 1
if c < count + 2:
continue
json_data = json.loads(line)
name = json_data["name"]
if name.startswith("AMD "):
name = name[4:] # Remove "AMD"
elif name.startswith("INTEL "):
name = name[6:] # Remove "INTEL"
driver.find_element(By.XPATH, "//*[@id=\"quicksearch\"]").clear()
driver.find_element(By.XPATH, "//*[@id=\"quicksearch\"]").send_keys(name)
time.sleep(0.5)
socket = "";
while True:
try:
socket = driver.find_element(By.XPATH, "//*[@id=\"ajaxresults\"]/table/tbody/tr/td[5]").text
break;
except:
try:
time.sleep(3)
if driver.find_element(By.XPATH, "//*[@id=\"ajaxresults\"]").text == "Nothing found.":
print("NOOOOOO")
socket = ""
break
except:
socket = ""
break
socket = ""
if socket.startswith("Socket "):
socket = socket[7:] # Remove Socket
modified_json_data = line[:-2] + ',"socket":\"' + socket + '\"}\n'
with open('cpu2.jsonl', 'a') as file:
# Append data to the file
print(modified_json_data)
file.write(modified_json_data)
time.sleep(random()*20 + 25)
print("Operation complete")