Skip to content Skip to sidebar Skip to footer

Python 3 - Can't Print Using The Re Library

I have this code: import requests from bs4 import BeautifulSoup import re url = 'http://www.rockefeller.edu/research/areas/summary.php?id=1' r = requests.get(url) soup = Beautifu

Solution 1:

re.compile() match case-sensitively by default. You got to set flag re.I to make it case-insensitive. See the following demo example :

import requests
from bs4 import BeautifulSoup
import re


url = "http://www.rockefeller.edu/research/areas/summary.php?id=1"
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')

for x in (soup.find_all(True,text=re.compile(r'comment', re.I))):
    print(x)

output :

<ahref="/about/comments">Comments</a>

Post a Comment for "Python 3 - Can't Print Using The Re Library"