我正在尝试制作网络刮刀,但我遇到了问题
# encoding=utf8
import urllib2
from bs4 import BeautifulSoup
indice = 0
print " "
quote_page = "https://www.bloomberg.com/quote/INDU:IND"
page = urllib2.urlopen(quote_page)
soup = BeautifulSoup(page, "html.parser")
print "down jones industries"
price_box = soup.find("div", attrs={"class": "price"})
price1 = price_box.text
print price1
divTag = soup.find_all("div", {"class": "cell cell__mobile-basic cell__visible__even"})
print divTag
in divTag:
indice = tag.find("div", {"class": "cell__value cell__value_"})
print indice
if price1 > indice :
print "UP"
elif price1 == indice :
print "equal"
elif price1 < indice :
print "DOWN"
print " "
quote_page = "link"
page = urllib2.urlopen(quote_page)
soup = BeautifulSoup(page, "html.parser")
print "google"
price_box = soup.find("div", attrs={"class": "price"})
price1 = price_box.text
print price1
divTag = soup.find_all("div", {"class": "cell cell__mobile-basic cell__visible__even"})
for tag in divTag:
indice = tag.find_all("div", {"class": "cell__value cell__value_"})
if price1 > indice :
print "UP"
elif price1 == indice :
print "equal"
elif price1 < indice :
print "DOWN"
print " "
quote_page = "link"
page = urllib2.urlopen(quote_page)
soup = BeautifulSoup(page, "html.parser")
print "ibovespa"
price_box = soup.find("div", attrs={"class": "price"})
price1 = price_box.text
print price1
divTag = soup.find_all("div", {"class": "cell cell__mobile-basic cell__visible__even"})
for tag in divTag:
indice = tag.find_all("div", {"class": "cell__value cell__value_"})
if price1 > indice :
print "UP"
elif price1 == indice :
print "equal"
elif price1 < indice :
print "DOWN"
print " "
quote_page = "https://www.bloomberg.com/quote/FB:US"
page = urllib2.urlopen(quote_page)
soup = BeautifulSoup(page, "html.parser")
print "facebook"
price_box = soup.find("div", attrs={"class": "price"})
price1 = price_box.text
print price1
divTag = soup.find_all("div", {"class": "cell cell__mobile-basic cell__visible__even"})
for tag in divTag:
indice = tag.find_all("div", {"class": "cell__value cell__value_"})
if price1 > indice :
print "UP"
elif price1 == indice :
print "equal"
elif price1 < indice :
print "DOWN"
print " "
` 这是我的代码,我遇到了一个问题:我想从特定的div标签中访问一个特定的div标签,有人可以帮助我!
答案 0 :(得分:0)