# -*- coding: utf-8 -*-
from urllib.request import urlopen, Request
import urllib
import bs4
location = 'Long-term'
enc_location = urllib.parse.quote (location + '+weather')
url = 'https://search.naver.com/search.naver?ie=utf8&query='+ enc_location
req = Request(url)
page = urlopen(req)
html = page.read()
soup = bs4.BeautifulSoup(html,'html5lib')
print ('current' + location +' fine dust' + soup.find('dd', class='lv1').find('span', class='num').text + '. ;)
File "", line 15 print ('current' + location +' fine dust' + soup.find('dd', class="lv1")).find('span', class="num").text + '. ;) ^ SyntaxError: invalid syntax
I don't know why syntax is coming up
crawling
The keyword class
is a reserved word in Python. It should not be used in other situations unless it is included in the string syntax or creates a real class.
There is a reserved word class
in a position where parser should not be in code parsing, so you spit out a grammar error.
If you look at the beautiful soup document,
The keyword arg that you can put in the find function is class_
. You can fix it with this.
https://www.crummy.com/software/BeautifulSoup/bs4/doc/#searching-by-css-class
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
620 Uncaught (inpromise) Error on Electron: An object could not be cloned
578 Understanding How to Configure Google API Key
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.