from Selenium Import the webdriver # Import keyboard Keys from selenium.webdriver.common.keys Import Keys Import Time Driver = webdriver.Chrome () # detector block the try : # Implicit wait, wait label loading driver.implicitly_wait ( 10 ) # To jingdong Home transmission request Driver. GET ( ' https://www.jd.com/ ' ) # id input by the input box lookup The input_tag = driver.find_element_by_id ( ' Key ' ) # send_keys pass the current tag value input_tag.send_keys ( ' China Dictionary ' ) # Press the keyboard's Enter key input_tag.send_keys (Keys.ENTER) the time.sleep ( 3 ) '' ' crawling Jingdong commodity information: doll name url price evaluation ' '' # Element to find a # elements looking more # Find all the product list good_list = driver.find_elements_by_class_name ( ' GL-Item ' ) # Print (good_list) # loop through each item for Good in good_list: # Find a product details page url by attribute selectors # url good_url = good.find_element_by_css_selector ('.p-img a').get_attribute('href') print(good_url) # 名称 good_name = good.find_element_by_css_selector('.p-name em').text print(good_name) # 价格 good_price = good.find_element_by_class_name('p-price').text print(good_price) # 评价数 good_commit = good.find_element_by_class_name('p-commit').text print(good_commit) str1 = f'' ' URL: {} good_url Name: {good_name} Price: {good_price} Evaluation: good_commit} { \ n- ' '' # in the commodity information written text with Open ( ' jd.txt ' , ' A ' , encoding = ' UTF-. 8 ' ) AS F: f.write (str1) the time.sleep ( 10 ) # exception capture the except exception AS E: Print (E) # browser will ultimately close off the driving the finally : driver.close ()