Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python soup

#Scrapes Python's URL, version number and logo from its Wikipedia page:

# $ pip3 install requests beautifulsoup4
import requests, bs4, os, sys

URL = 'https://en.wikipedia.org/wiki/Python_(programming_language)'
try:
    html       = requests.get(URL).text
    document   = bs4.BeautifulSoup(html, 'html.parser')
    table      = document.find('table', class_='infobox vevent')
    python_url = table.find('th', text='Website').next_sibling.a['href']
    version    = table.find('th', text='Stable release').next_sibling.strings.__next__()
    logo_url   = table.find('img')['src']
    logo       = requests.get(f'https:{logo_url}').content
    filename   = os.path.basename(logo_url)
    with open(filename, 'wb') as file:
        file.write(logo)
    print(f'{python_url}, {version}, file://{os.path.abspath(filename)}')
except requests.exceptions.ConnectionError:
    print("You've got problems with connection.", file=sys.stderr)
Comment

PREVIOUS NEXT
Code Example
Python :: web scraping python beautifulsoup 
Python :: binary representation python 
Python :: dataframe KeyError: 
Python :: how to invert plot axis python 
Python :: save list to dataframe pandas 
Python :: count list python 
Python :: python recursively print directory 
Python :: numpy logspace 
Python :: how to sort a dictionary using pprint module in python 
Python :: flask python use specified port 
Python :: remove last element from list python 
Python :: python location 
Python :: cv2.namedWindow 
Python :: how to split a string by character in python 
Python :: what does .shape do in python 
Python :: ros python service server 
Python :: pandas dataframe get number of occurrence in column 
Python :: leap year 
Python :: sys.path.append python 
Python :: delete tuple from list 
Python :: SystemError: tile cannot extend outside image 
Python :: how to create enter pressed for qlineedit in pyqt5 
Python :: difference between supervised and unsupervised learning 
Python :: django python base 64 decode 
Python :: find factorial in python 
Python :: split a string with 2 char each in python 
Python :: Python t date from a timestamp 
Python :: how to get time in python 
Python :: drop first two rows pandas 
Python :: pyqt5 button connect 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =