Skip to content
Closed
Changes from 1 commit
Commits
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
finished chap 3-3
  • Loading branch information
masamichiIto committed Oct 5, 2023
commit 72b35c9b0dbdf47508c2185d1ea9e7c5282bf903
25 changes: 24 additions & 1 deletion chap3_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,27 @@ def followExternalOnly(startingSite):
print('Random external link is: {}'.format(externalLink))
followExternalOnly(externalLink)

followExternalOnly('http://oreilly.com')
#followExternalOnly('http://oreilly.com')
## このサイトで見つかったすべての外部URLのリストを集める
allExtLinks = set()
allIntLinks = set()

def getAllExternalLinks(siteUrl):
html = urlopen(siteUrl)
domain = '{}://{}'.format(urlparse(siteUrl).scheme, urlparse(siteUrl).netloc)
bs = BeautifulSoup(html, 'html.parser')
internalLinks = getInternalLinks(bs, domain)
externalLinks = getExternalLinks(bs, domain)

for link in externalLinks:
if link not in allExtLinks:
allExtLinks.add(link)
print(link)

for link in internalLinks:
if link not in allIntLinks:
allIntLinks.add(link)
getAllExternalLinks(link)

allIntLinks.add('http://oreilly.com')
getAllExternalLinks('http://oreilly.com')