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 tkinter disable dropdown 
Python :: python 3 of 4 conditions true 
Python :: streamlit button to load a file 
Python :: flask oneid 
Python :: subprocess the system cannot find the file specified 
Python :: how to change colour of rows in csv using pandas 
Python :: python detect color on screen 
Python :: python numpy reverse an array 
Python :: yesno django 
Python :: absolute value of int python 
Python :: How to count occurences of a certain item in a numpy array 
Python :: get number of bits on integer in python 
Python :: create a dataframe with series 
Python :: pandas read ods 
Python :: how to change cursor on hover of button in tkinter 
Python :: how to save the history of keras model 
Python :: pandas read csv unamed:o 
Python :: django getting started 
Python :: kaaba python tutorial 
Python :: python inheritance remove an attribute 
Python :: how to see if a proxy is up in python 
Python :: python random phone number 
Python :: how to make nmap port scanner in python 
Python :: pyspark select without column 
Python :: python write requests response to text file 
Python :: notify2 python example 
Python :: install log21 python 
Python :: selenium scroll to element python 
Python :: how to calculate mean in python 
Python :: elon son name 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =