37,720
社区成员
发帖
与我相关
我的任务
分享
#coding=utf-8
import urllib2
import requests
import lxml
from bs4 import BeautifulSoup
url= "http://www.weather.com.cn/weather/101220304.shtml" #构造网址 网站meta utf-8编码
req=requests.get(url).text
soup=BeautifulSoup(req,'html.parser')
for inpu in soup.findAll('ul',class_='t clearfix'):
for text in inpu.stripped_strings:
#print type(text) 这里显示type(text)为unicode
print text.decode('utf-8')
#!/usr/bin/python
# -*- coding:utf-8 -*-
from urllib import request
import re
url= "http://www.weather.com.cn/weather/101220304.shtml"
req = request.Request(url)
html = request.urlopen(req).read().decode('utf-8')
#print(html)
patt=re.compile(r'<ul class="t clearfix">(.*?)</ul>',re.S)
res=patt.findall(html)
print(res)
with open('zz.txt','w') as f:
f.write(res[0])
#coding=utf-8
import urllib2
import requests
import lxml
from bs4 import BeautifulSoup
url= "http://www.weather.com.cn/weather/101220304.shtml" #构造网址 网站meta utf-8编码
req=requests.get(url)
req.encoding = 'utf-8'
soup=BeautifulSoup(req.text,'html.parser')
for inpu in soup.findAll('ul',class_='t clearfix'):
for text in inpu.stripped_strings:
#print type(text) #这里显示type(text)为unicode
print text
response = requests.get(url)
response.encoding = 'utf-8'