Skip to content

Commit 1799dbf

Browse files
committed
adicionando codes exemplos
1 parent a8e16bc commit 1799dbf

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from urllib.request import urlopen
2+
from bs4 import BeautifulSoup
3+
print()
4+
html = urlopen('http://www.pythonscraping.com/pages/page1.html')
5+
bs = BeautifulSoup(html.read(), 'html.parser')
6+
# nameList = bs.findAll(['h1', 'h2', 'h3', 'h4', 'h5', 'h6'])
7+
# nameList = bs.findAll('span', {'class': {'green', 'red'}})
8+
# nameList = bs.findAll(text='the prince')
9+
# print(len(nameList))
10+
title = bs.findAll(id='title', class_='text')
11+
print(len(title))
12+
13+
14+
# for name in nameList:
15+
# print(name.get_title())
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from urllib.request import urlopen
2+
from bs4 import BeautifulSoup
3+
4+
html = urlopen('http://pythonscraping.com/pages/page3.html')
5+
bs = BeautifulSoup(html, 'html.parser')
6+
7+
8+
print('\nexibindo lista das linhas de produtos de "giftList"')
9+
for child in bs.find('table', {'id': 'giftList'}).children:
10+
print(child)

02-parsingDeHTMLAvancado/1-outrasUtilidadesDoBeautifulSoup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
print()
44
html = urlopen('http://www.pythonscraping.com/pages/page1.html')
55
bs = BeautifulSoup(html.read(), 'html.parser')
6-
nameList = bs.findAll('span', {'class': 'green'})
6+
# nameList = bs.findAll('span', {'class': 'green'})
7+
nameList = bs.findAll('', {'class': 'green'})
8+
79

810
for name in nameList:
9-
print(name.get_text())
11+
print(name.get_title())

0 commit comments

Comments
 (0)