Scraping text in h3 and div tags using beautifulSoup, Python

后端 未结 3 864
忘掉有多难
忘掉有多难 2020-12-31 20:51

I have no experience with python, BeautifulSoup, Selenium etc. but I\'m eager to scrape data from a website and store as a csv file. A single sample of data I need is coded

3条回答
  •  猫巷女王i
    2020-12-31 21:25

    So it seemed quite nice:

        #  -*- coding: utf-8 -*-
        # by Faguiro #
        # run using Python 3.8.6  on Linux#
        import requests
        from bs4 import BeautifulSoup
    
        # insert your site here
        url= input("Enter the url-->")
    
        #use requests
        r = requests.get(url)
        content = r.content
    
        #soup!
        soup = BeautifulSoup(content, "html.parser")
    
        #find all tag in the soup.
        heading = soup.find_all("h3")
    
        #print(heading) <--- result...
    
        #...ptonic organization!
        n=len(heading)
        for x in range(n): 
            print(str.strip(heading[x].text))
    

    Dependencies: On terminal (linux):

    sudo apt-get install python3-bs4

提交回复
热议问题