mercredi 18 avril 2018

If statement to match String in bs4 output

Need some assistance. I have a function where I use the find_all function on my bs object to print some specific html. my goal here is to eventually match the productName and color together so I can go to the correct link but I am having some trouble picking out the correct word. Here is my code and I get no output when I run this.

def getPremeProduct() -> str:
session = requests.Session()
base = "http://www.supremenewyork.com"
r = session.get('http://www.supremenewyork.com/shop/all/accessories')
soup = BeautifulSoup(r.content, 'lxml')
keyword = input('Input your keyword: ')
color = str(input('input your color: '))
productColor = soup.findAll('p', text=re.compile(r'\bChecker\b'))
productName = soup.findAll('a', text=re.compile(r'\bTees\b'))

if "Checker" in productName:
    print(productName)

### Here are the outputs for productName
#<a class="name-link" href="/shop/accessories/s4o3fjcg0/eq35gubw7">Supreme®/Hanes® Checker Tagless Tees (2 Pack)</a>
#<a class="name-link" 
href="/shop/accessories/hz7wj2ui4/jx7qm1hsc">Supreme®/Hanes® Tagless Tees 
(3 Pack)</a>

href="/shop/accessories/hz7wj2ui4/yks6zay73">Supreme®/Hanes® Tagless Tees (3 Pack)</a>

Anyone have any ideas why my if statement isn't printing out just the one result that has "Checker" included? Thanks

Aucun commentaire:

Enregistrer un commentaire