Yogi Dwinanto
Yogi Dwinanto

Reputation: 1

Invalid python syntax while using beautifulsoup

I wrote the following code:

produk = soup.find_all("div","col-lg-3 col-md-4 col-sm-6 bt-product-list")
i = 1
for p in produk:
    print p.find('div','bt-product-list-info').get_text()
    print p.find('div','col-md-3 col-xs-12 bt-product-list-price')

This returns the following error:

File "<ipython-input-3-1db13187c15e>", line 4
    print p.find('div','bt-product-list-info').get_text()
          ^
SyntaxError: invalid syntax

Upvotes: 0

Views: 84

Answers (1)

Daniel Finch
Daniel Finch

Reputation: 443

You are most likely using Python 3, in which print is a function rather than a statement. You would need to modify your code to look like this:

produk = soup.find_all("div","col-lg-3 col-md-4 col-sm-6 bt-product-list")
i = 1
for p in produk:
    print(p.find('div','bt-product-list-info').get_text())
    print(p.find('div','col-md-3 col-xs-12 bt-product-list-price'))

Upvotes: 1

Related Questions