Skip to content

Commit ab48ad1

Browse files
committed
Updating example to work with new website.
1 parent df7e15f commit ab48ad1

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

‎README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ Feel free to help building up the repository with more content suited for traini
4848
History
4949
-------------------
5050

51+
v2.0.3 (2016-10-05)
52+
53+
* Updating example `example/scrape` to work with new website.
54+
55+
5156
v2.0.2 (2016-09-29)
5257

5358
* Adding `example/image` with example creating ascii image.

‎example/scrape/irc-from-dbwebb.py‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
24
"""
35
Show off how to scrape information from a webpage.
46
"""
@@ -15,7 +17,7 @@
1517

1618

1719
# Get webpage
18-
url = "http://cc1.dbwebb.se/"
20+
url = "https://dbwebb.se/irclog/"
1921
print("\nReady to send HTTP request to ", url, "\nPress enter to continue. ", end='')
2022
input()
2123
req = requests.get(url)
@@ -24,16 +26,13 @@
2426

2527

2628
# Get the webpage content as a soup
27-
soup = BeautifulSoup(req.text)
28-
29-
ircLog = soup.find("p", class_="irclog")
30-
print("\nThe scraped content (the irclog) is:\n", ircLog)
31-
32-
entries = ircLog("span")
29+
soup = BeautifulSoup(req.text, "html5lib")
3330

34-
str1 = "{time} <{user}> {message}"
31+
# Find the intresting parts in the soup
32+
ircLog = soup.find("tbody")
33+
logText = [element.text for element in ircLog.tr.findAll("td")]
3534

36-
print("\nPretty print log details:")
37-
print(str1.format(time=entries[0].text, user=entries[1].text, message=entries[2].text))
38-
print(str1.format(time=entries[3].text, user=entries[4].text, message=entries[5].text))
39-
print(str1.format(time=entries[6].text, user=entries[7].text, message=entries[8].text))
35+
# Print out the content
36+
formatString = "{} <{}> {}"
37+
print("\nLast entry in IRC-log:")
38+
print(formatString.format(*logText))

0 commit comments

Comments
 (0)