Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python beautiful

#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 :: instance variable in python 
Python :: how to get key of a particular value in dictionary python using index 
Python :: how to create a python script to automate software installation? 
Python :: what is instance variable in python 
Python :: load json py 
Python :: delete virtual environment in python windows 
Python :: split pandas row into multiple rows 
Python :: hex to rgb python 
Python :: python all lowercase letters 
Python :: pymupdf extract all text from pdf 
Python :: convert python float list to 2 digit 
Python :: telebot send file 
Python :: python create function 
Python :: split string in python 
Python :: fromkeys in python 
Python :: Python remove punctuation from a string 
Python :: vscode pylint missing module docstring 
Python :: unique_together what is used of it in django 
Python :: string count substring occurences pytohn 
Python :: delete tuple from list python 
Python :: pyqt open file dialog 
Python :: python import from parent directory 
Python :: replace key of dictionary python 
Python :: Python Format date using strftime() 
Python :: writerows to existing csv python 
Python :: set type of column pandas 
Python :: How to loop over grouped Pandas dataframe? 
Python :: python multiline comment 
Python :: how to scrape multiple pages using selenium in python 
Python :: python count items in list 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =