#查找http://money.cnn.com/data/dow30/中公司名称代码和股票价格
import requests,re
from bs4 import BeautifulSoup
r = requests.get('http://money.cnn.com/data/dow30/')
r.raise_for_status()
soup = BeautifulSoup(r.text,'html.parser')
list1 = [] #查找超链接内容
for item in soup.findAll('a',{'class':'wsod_symbol'}):
list1.append(item.get_text())
list2 = [] #查找pirce
for price in soup.findAll ('span',{'stream':re.compile('last_(.*)')}): #span标签的 stream属性使用正则
list2.append(price.get_text())
tups = zip(list1,list2)
for i,j in tups :
print(i,j)
import requests,re
from bs4 import BeautifulSoup
r = requests.get('http://money.cnn.com/data/dow30/')
r.raise_for_status()
soup = BeautifulSoup(r.text,'html.parser')
list1 = [] #查找超链接内容
for item in soup.findAll('a',{'class':'wsod_symbol'}):
list1.append(item.get_text())
list2 = [] #查找pirce
for price in soup.findAll ('span',{'stream':re.compile('last_(.*)')}): #span标签的 stream属性使用正则
list2.append(price.get_text())
tups = zip(list1,list2)
for i,j in tups :
print(i,j)