0

The error:

Traceback (most recent call last):
   File "C:\Users\gavin\AppData\Local\Temp\atom_script_tempfiles\2c36e7c0-6099-11ea-9ee3-eff5d5088bc9", line 35, in <module>
     print(title + ' ' + color + price + ' ' + price)
   File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.752.0_x64__

here's my code

import bs4
import requests
import csv
url = requests.get('https://www.flipkart.com/search?q=lego&otracker=search&otracker1=search&marketplace=FLIPKART&as-show=on&as=off')
soup = bs4.BeautifulSoup(url.text, 'html.parser')
containers = soup.select('._3liAhj')
for container in containers:
    titles = container.select('._2cLu-l')
    title = titles[0].text.strip()

    colors = container.select('._1rcHFq')
    color = colors[0].text.strip()

    prices = container.select('._1vC4OE')
    price = prices[0].text

print(title + ' ' + color + price + ' ' + price)
wjandrea
  • 28,235
  • 9
  • 60
  • 81
Gavin
  • 9
  • @Erik I rolled back your edit cause you removed the error message (even though it's incomplete). You also added an extra indentation level on the code. – wjandrea Mar 07 '20 at 22:48
  • 1
    Welcome to Stack Overflow! Check out the [tour] and [ask]. That error message is incomplete. Please [edit] the question to fix it. See [mre] for reference. – wjandrea Mar 07 '20 at 22:50
  • Thanks @wjandrea, new at the editing... I would add back the beautifulsoup tag, you may get more experts helping out. @Gavin, I'm not getting an error on my Mac, there may be an issue with your terminal. To remove any non-ascii try `price = re.sub(r'[^\x00-\x7f]',r'', prices[0].text)` and add `import re` at the top. See https://stackoverflow.com/questions/8689795/how-can-i-remove-non-ascii-characters-but-leave-periods-and-spaces-using-python ` – ErikE Mar 08 '20 at 02:56

0 Answers0