<jupyter_start><jupyter_text>from urllib.request import urlopenfrom bs4 import BeautifulSouphtml = urlopen('http://www.pythonscraping.com/pages/warandpeace.html')bs = BeautifulSoup(html, 'html.parser')print(bs)<jupyter_code>from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen('http://www.pythonscraping.com/pages/warandpeace.html')
bs = BeautifulSoup(html, "html.parser")
nameList = bs.findAll('span', {'class': 'green'})
for name in nameList:
    print(name.get_text())
titles = bs.find_all(['h1', 'h2','h3','h4','h5','h6'])
print([title for title in titles])

allText = bs.find_all('span', {'class':{'green', 'red'}})
print([text for text in allText])
nameList = bs.find_all(text='the prince')
print(len(nameList))
title = bs.find_all(id='title', class_='text')
print([text for text in allText])
from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen('http://www.pythonscraping.com/pages/page3.html')
bs = BeautifulSoup(html, 'html.parser')

for child in bs.find('table',{'id':'giftList'}).children:
    print(child)
from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen('http://www.pythonscraping.com/pages/page3.html')
bs = BeautifulSoup(html, 'html.parser')

for sibling in bs.find('table', {'id':'giftList'}).tr.next_siblings:
    print(sibling) 
from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen('http://www.pythonscraping.com/pages/page3.html')
bs = BeautifulSoup(html, 'html.parser')
print(bs.find('img',
              {'src':'../img/gifts/img1.jpg'})
      .parent.previous_sibling.get_text())
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re

html = urlopen('http://www.pythonscraping.com/pages/page3.html')
bs = BeautifulSoup(html, 'html.parser')
images = bs.find_all('img', {'src':re.compile('\.\.\/img\/gifts/img.*\.jpg')})
for image in images: 
    print(image['src'])
bs.find_all(lambda tag: len(tag.attrs) == 2)
bs.find_all(lambda tag: tag.get_text() == 'Or maybe he\'s only resting?')
bs.find_all('', text='Or maybe he\'s only resting?')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17286858219500706, 'fraction_numerical': 0.008478568064060292, 'mean_word_length': 5.742857142857143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '136569', 'license': 'MIT', 'n_tokens_mistral': 773, 'n_tokens_neox': 762, 'n_words': 154, 'path': 'WebScraping/Chapter02-AdvancedHTMLParsing.ipynb', 'repo_name': 'ValRCS/RCS_Python_11', 'size': '2123'}