Import the webdriver Selenium from # 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/') # Find input by the input box ID 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 to find more # Find all the products list = driver.find_elements_by_class_name good_list ( 'GL-Item') # Print (good_list) # loop through each item for in good_list Good: # Find product details page by url attribute selector # url good_url = good.find_element_by_css_selector ( 'p-. A IMG '). get_attribute (' the href ') Print (good_url) # name good_name = good.find_element_by_css_selector ('. P-name EM '). text Print (good_name) # price good_price = good.find_element_by_class_name (' p-price ' ) .text Print (good_price) # evaluation number good_commit = good.find_element_by_class_name ( 'the commit-P') 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) # catch exception except Exception as E: Print (E) # will ultimately drive the browser closes off a finally: driver.close ()