import urllib.request
from bs4 import BeautifulSoup
url="http://roll.finance.qq.com/"
html=urllib.request.urlopen(url)
response=html.read()
soup=BeautifulSoup(response,'lxml')
print(soup)
import urllib.request
from bs4 import BeautifulSoup
url="http://roll.finance.qq.com/"
html=urllib.request.urlopen(url)
response=html.read()
soup=BeautifulSoup(response,'lxml')
print(soup)
大概是缺了HTTP Header,使用requests库就没有这个问题了。
这段代码亲测没有问题