Skip to content
Closed
Show file tree
Hide file tree
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
chap3 started
  • Loading branch information
masamichiIto committed Aug 23, 2023
commit 90bfc7aa1d1110bab61f738132da153bada546e6
3 changes: 2 additions & 1 deletion chap2_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
## chap2-4: regular expression
images = bs.find_all('img', {'src':re.compile('..\/img\/gifts\/img.*.jpg')})
for image in images:
print(image['src'])
print(image['src'])

10 changes: 10 additions & 0 deletions chap3_work.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re

html = urlopen('http://en.wikipedia.org/wiki/Kevin_Bacon')
bs = BeautifulSoup(html, 'html.parser')
for link in bs.find('div', {'id':'bodyContent'}).find_all('a', href=re.compile('^(/wiki/)((?!:).)*$')):
# ?!から始まる文字列を()で囲むことで,その文字列を含まないを表現できる.(?!:).で1つのコロンを含まない,((?!:).)*コロン以外の0文字以上の文字列を表している
if 'href' in link.attrs:
print(link.attrs['href'])