Python uses crawlers to get all the countries in the page drop-down box

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.