Python Selenium embarrassing Encyclopedia

Source: Internet
Author: User

A simple crawler entry code to crawl the jokes on the wiki homepage (excluding images, text only)

  1. Selenium and Chromedriver need to be installed.
  2. Place the Chromedriver.exe in the Chrome installation directory.
  3. Configure environment variables. Click My Computer, Properties--Advanced system Settings->path-> new (Chrome installation location, like mine is: C:\Program Files (x86) \google\chrome\application)
    #/usr/bin/env python#Coding:utf-8#Import Selenium fromSeleniumImportWebdriverclassQiubai:def __init__(self):#Open Chrome BrowserSelf.dr =Webdriver. Chrome ()#visit the Embarrassing Encyclopedia homepageSelf.dr.get ('https://www.qiushibaike.com/')    defprint_content (self):#get the element with ID "Content-left"Main_content = self.dr.find_element_by_id ('Content-left')        #get the element with class "content"Contents = Main_content.find_elements_by_class_name ('content')        #what is obtained through the For loop outputi = 1 forContentinchContents:Print(Str (i) +"."+ Content.text +'\ n') I+ = 1self.quit ()defQuit (self):#Close Browserself.dr.quit () Qiubai (). Print_content ( )

Python Selenium embarrassing Encyclopedia

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.