Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python scraping

#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

Python Script to Scrape Data From Website

import os
import requests
from bs4 import BeautifulSoup
url = "https://www.google.com/"
reponse = requests.get(url)
if reponse.ok:
 soup = BeautifulSoup(reponse.text, "lxml")
 title = str(soup.find("title"))
 title = title.replace("<title>", "")
 title = title.replace("</title>", "")
 print("The title is : " + str(title))
os.system("pause")
Comment

web scraping using python code

>>> from bs4 import BeautifulSoup
>>> raw_html = open('contrived.html').read()
>>> html = BeautifulSoup(raw_html, 'html.parser')
>>> for p in html.select('p'):
...     if p['id'] == 'walrus':
...         print(p.text)

'I am the walrus'


import requests
from bs4 import BeautifulSoup

URL = 'https://www.monster.com/jobs/search/?q=Software-Developer&where=Australia'
page = requests.get(URL)

soup = BeautifulSoup(page.content, 'html.parser')
Comment

python web scraping

	#Run request
	url = "https://nanolooker.com/account/" + address
    response = requests.get(url)

    if response.ok:
        # Make some soup
    	soup = BeautifulSoup(response.text, "lxml")

        #Show the title
    	print("The title is: " + str(soup.title.string))
Comment

PREVIOUS NEXT
Code Example
Python :: beautifulsoup get h1 
Python :: python condition question 
Python :: python jinja2 from string 
Python :: python string encode 
Python :: list of lists to table python 
Python :: python keyboard hold key 
Python :: list to dic 
Python :: pandas if value present in df index 
Python :: iterate through a list and print from index x to y using for loop python 
Python :: how to append two pandas dataframe 
Python :: while python 
Python :: plot path in pillow python 
Python :: clear variable jupyter notebook 
Python :: Python __mul__ magic method 
Python :: exponential python 
Python :: python unpacking 
Python :: sumof product 1 
Python :: iterrrows 
Python :: django form field add attrs 
Python :: check if a file exists in python 
Python :: create an empty array numpy 
Python :: python bool 
Python :: python how to make integer show 2 numbers 
Python :: validate longitude and latitude in python 
Python :: python program to display fibonacci sequence using recursion 
Python :: jsonresponse django 
Python :: filter dataframe with a list of index 
Python :: knuth morris pratt algorithm 
Python :: Split the string using the separator 
Python :: python readlines strip 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =