使用py3版本的python,pip instsall urllib3后,加载urllib库;
py3的url整合了urllib2和urlparse等五个模块,所以urlopen就不能用了;
读网页用:
import urllib.request
get = urllib,request.urlopen("http://www.app-echo.com/#/sound/152466").read()
print(get)
即可打印;
完整例子:
import itchat from bs4 import BeautifulSoup import requests
@itchat.msg_register(itchat.content.TEXT) def Send2Wechat(msg): url = 'https://www.jubi.com/shanzhaibi/' webdata = requests.get(url).text soup = BeautifulSoup(webdata, 'lxml') new_title = soup.select("div.new_list > ul > li > a.title") for n in new_title: title = n.get_text() itchat.send('%s' % title) break itchat.auto_login() itchat.run()