-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselenium_test.py
More file actions
41 lines (29 loc) · 1.2 KB
/
selenium_test.py
File metadata and controls
41 lines (29 loc) · 1.2 KB
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
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import openpyxl
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
def main():
service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=options)
driver.get("https://danawa.com/")
search_tag = driver.find_element(By.CLASS_NAME, "search__input")
search_tag.send_keys("RTX 3080")
search_tag.send_keys(Keys.ENTER)
count = 1
PageNo = 3
for i in range(count, PageNo):
driver.execute_script("getPage("+str(i)+")")
time.sleep(1)
itemList = driver.find_elements(By.CLASS_NAME, "prod_item")
for item in itemList:
if item.get_attribute("id") != "":
name = item.find_element(By.CLASS_NAME, "prod_name").text
price = item.find_element(By.CLASS_NAME, "price_sect").find_element(By.TAG_NAME, "a").text
print(name, "/", price)
if __name__ == '__main__':
main()