Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cc1eb44
Move notebook to chapter1 folder
will-i-amv Jun 30, 2021
ba2dd87
Add 1st example to chapter1
will-i-amv Jun 30, 2021
874d3bb
Add 2nd example to chapter1
will-i-amv Jun 30, 2021
4121156
Add 3rd example to chapter1
will-i-amv Jun 30, 2021
09a9365
Add 4th example to chapter1
will-i-amv Jun 30, 2021
71ced46
Move notebook to chapter2 folder
will-i-amv Jun 30, 2021
47fbd43
Add 1st example to chapter2
will-i-amv Jun 30, 2021
0642548
Add 2nd example to chapter2
will-i-amv Jun 30, 2021
d1a874b
Add 3rd example to chapter2
will-i-amv Jun 30, 2021
5339a19
Add 4th example to chapter2
will-i-amv Jun 30, 2021
4d44423
Add 5th example to chapter2
will-i-amv Jun 30, 2021
e14730f
Add 6th example to chapter2
will-i-amv Jun 30, 2021
1e8db88
Add 7th example to chapter2
will-i-amv Jun 30, 2021
aec4ac7
Delete chapter2's notebook
will-i-amv Jun 30, 2021
5948047
Delete chapter1's notebook
will-i-amv Jun 30, 2021
54d62e6
Merge pull request #1 from will-i-amv-books/test
will-i-amv Jun 30, 2021
1360c6a
Move notebook to v2/chapter3
will-i-amv Jul 1, 2021
f683f24
Add 1st example to chapter3
will-i-amv Jul 1, 2021
1c133a6
Add 2nd example to chapter3
will-i-amv Jul 1, 2021
0261402
Add 3rd example to chapter3
will-i-amv Jul 1, 2021
108b604
Add 4th example to chapter3
will-i-amv Jul 1, 2021
9389220
Add 5th example to chapter3
will-i-amv Jul 1, 2021
c01d688
Add 6th example to chapter3
will-i-amv Jul 1, 2021
384171c
Move from v1 to v2 folder
will-i-amv Jul 1, 2021
2812eea
Add 7th example to chapter3
will-i-amv Jul 1, 2021
00715d8
Move notebook to v2/chapter4
will-i-amv Jul 2, 2021
6e7e293
Add back chapter1's notebook
will-i-amv Jul 2, 2021
3738c31
Add back chapter2's notebook
will-i-amv Jul 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add 3rd example to chapter3
  • Loading branch information
will-i-amv authored Jul 1, 2021
commit 026140240e0e9103a1f83a8853742d89ceb295d1
20 changes: 20 additions & 0 deletions v2/chapter3/3-getRandomLinks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from urllib.request import urlopen
from bs4 import BeautifulSoup
import datetime
import random
import re


def getLinks(articleUrl):
html = urlopen('http://en.wikipedia.org{}'.format(articleUrl))
bs = BeautifulSoup(html, 'html.parser')
regex = re.compile('^(/wiki/)((?!:).)*$')
return bs.find('div', {'id':'bodyContent'}).find_all('a', href=regex)


random.seed(datetime.datetime.now())
links = getLinks('/wiki/Kevin_Bacon')
while len(links) > 0:
newArticle = links[random.randint(0, len(links)-1)].attrs['href']
print(newArticle)
links = getLinks(newArticle)