-1
我試圖做一個網站刮板,但我有問題acessing從特定的div父特定div標籤(美麗的湯蟒蛇)
# 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標籤父母可以有人請幫助我!
分享你的研究可以幫助每個人。告訴我們你試過的東西以及爲什麼 它不符合你的需求。這表明你已經花時間 試圖幫助自己,它使我們避免重申明顯的答案, ,最重要的是它可以幫助您獲得更具體和相關的答案! 另請參見:[問] – glennsl