Python????????????????????
???????????? ???????[ 2014/2/27 9:23:16 ] ????????????? Python ????
??????????????????????????????????У???????????????????????????????????????????????????渵?????
??????????????????????????utf-8??
????1. ????
????2. ?????????
????3. ???????????
????4. ???????????
???????????????£?
????1. ????????????utf-8???????????????仰
????# -*- coding:utf8 -*-
????#??????????????????????
????2. ????????????????utf-8?????д
????conn=MySQLdb.connect(host='localhost'??user='root'??passwd='****'??db='kfxx'??port=3306??charset='utf8')
????cur=conn.cursor()
????3. ????????????????utf-8?????????????????
????4. ????????????????utf-8????????????????????utf-8?????????????utf-8
????#???????????
html_1 = urllib2.urlopen(cityURL??timeout=120).read()
mychar = chardet.detect(html_1)
bianma = mychar['encoding']
if bianma == 'utf-8' or bianma == 'UTF-8':
html = html_1
else :
html = html_1.decode('gb2312'??'ignore').encode('utf-8')
chapter_soup = BeautifulSoup(html)
city = chapter_soup.find('div'??class_ = 'row-fluid').find('h1').get_text()
province = chapter_soup.find('a'??class_ = 'province').get_text()
pmNum = chapter_soup.find('div'??class_ = 'row-fluid').find('span').get_text()
suggest = chapter_soup.find('div'??class_ = 'row-fluid').find('h2').get_text()
rand = chapter_soup.find('div'??class_ = 'row-fluid').find('h2').find_next_sibling('h2').get_text()
face = chapter_soup.find('div'??class_ = 'span4 pmemoji').find('h1').get_text()
conclusion = chapter_soup.find('h1'??class_ = 'review').get_text()
print city.encode('utf-8')
cur.execute('insert into t_pm values(''+city.encode('utf-8')
+''??''+province.encode('utf-8')
+''??''+pmNum.encode('utf-8')
+''??''+suggest.encode('utf-8')
+''??''+rand.encode('utf-8')
+''??''+conclusion.encode('utf-8')+'')')
?????????????????????????????Ч?????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11