Some time ago, the leader said a list of all the country information on a page, saying that the country drop-down box of the country has two hundred or three hundred, is a third-party module import, manual Copy from the page, unrealistic, and then want to use the crawler to get this country information, and save to the file.
Below is the specific code, write is also relatively simple, using the Selenium Operation page, get the dropdown country list information, and save to the file
fromSeleniumImportWebdriverImportXlwtdriver= Webdriver. Chrome ('C:\Program Files (x86) \google\chrome\application\chromedriver.exe') Driver.get ('https://xxx.xx.com/contact') Countries= driver.find_element_by_id ('Country')#Get Country DropDownListOptions_list = Countries.find_elements_by_tag_name ('option') Options= [] forOptioninchOptions_list:#get all the data in country DropDownListOptions.append (Option.text) with open ('Country_list.txt','w+', encoding='Utf-8') as F: forIinchOptions:ifI! ='Select Your country': F.write (i+'\ n') Driver.quit ()
Python uses crawlers to get all the countries in the page drop-down box