Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

scrape with beautiful soup

from bs4 import BeautifulSoup 
import requests 
page = requests.get("https://www.google.dz/search?q=see") 
soup = BeautifulSoup(page.content) 
links = soup.findAll("a") 
for link in links: 
    if link['href'].startswith('/url?q='): 
        print (link['href'].replace('/url?q=',''))
Comment

web scraping python beautifulsoup

#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

scraping python beautifulsoup

#import requests module to send request to the website
import requests
#from bs4 module import BeautifulSoup class 
from bs4 import BeautifulSoup
r = requests.get(url=<website_url_here>).content
#server will send response and content is stored in 'r' object
#Use BeautifulSoup class with 'html.prser' or 'lxml'
soup = BeautifulSoup(r, 'html.parser')
Comment

PREVIOUS NEXT
Code Example
Python :: python float print 2 digits 
Python :: Using python permutations function on a list 
Python :: pandas add quantile columns 
Python :: colorbar font size python 
Python :: for i 
Python :: python pad with spaces 
Python :: move items from one list to another python 
Python :: convert all images in folder to jpg python 
Python :: insert data in table python 
Python :: python - remove floating in a dataframe 
Python :: tuple length in python 
Python :: add fonts to matplotlib from a particular location 
Python :: python read integer from stdin 
Python :: django static files 
Python :: python hide input 
Python :: python url shortener 
Python :: python cmd exec 
Python :: python declare array of size n 
Python :: print dictionary of list 
Python :: chatbot python 
Python :: python how to count all elements in a list 
Python :: how to generate random numbers in python 
Python :: how to add window background in pyqt5 
Python :: hot to check tkinter verionin python 
Python :: how to get the first key of a dictionary in python 
Python :: Python datetime to string using strftime() 
Python :: filter one dataframe by another 
Python :: python path to python executable 
Python :: finding factorial of a number in python 
Python :: pygame.draw.rect() 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =