मैं इस साइट से जानकारी (एचटीएमएल टेबल) पार्स करने के लिए कोशिश कर रहा हूँ: http://www.511virginia.org/RoadConditions.aspx?j=All&r=1BeautifulSoup HTML तालिका पार्स
वर्तमान में मैं BeautifulSoup उपयोग कर रहा हूँ और मैं इस कोड
from mechanize import Browser
from BeautifulSoup import BeautifulSoup
mech = Browser()
url = "http://www.511virginia.org/RoadConditions.aspx?j=All&r=1"
page = mech.open(url)
html = page.read()
soup = BeautifulSoup(html)
table = soup.find("table")
rows = table.findAll('tr')[3]
cols = rows.findAll('td')
roadtype = cols[0].string
start = cols.[1].string
end = cols[2].string
condition = cols[3].string
reason = cols[4].string
update = cols[5].string
entry = (roadtype, start, end, condition, reason, update)
print entry
मुद्दे के साथ है की तरह दिखता है प्रारंभ और अंत कॉलम। वे सिर्फ "कोई नहीं" के रूप में मुद्रित करने के
आउटपुट:
(u'Rt. 613N (Giles County)', None, None, u'Moderate', u'snow or ice', u'01/13/2010 10:50 AM')
मुझे पता है कि वे कॉलम सूची में संग्रहीत है, लेकिन यह है कि अतिरिक्त लिंक टैग मूल html देख के साथ पार्स अप खिलवाड़ कर रहा है लगता है
<td headers="road-type" class="ConditionsCellText">Rt. 613N (Giles County)</td>
<td headers="start" class="ConditionsCellText"><a href="conditions.aspx?lat=37.43036753&long=-80.51118005#viewmap">Big Stony Ck Rd; Rt. 635E/W (Giles County)</a></td>
<td headers="end" class="ConditionsCellText"><a href="conditions.aspx?lat=37.43036753&long=-80.51118005#viewmap">Cabin Ln; Rocky Mount Rd; Rt. 721E/W (Giles County)</a></td>
<td headers="condition" class="ConditionsCellText">Moderate</td>
<td headers="reason" class="ConditionsCellText">snow or ice</td>
<td headers="update" class="ConditionsCellText">01/13/2010 10:50 AM</td>
तो क्या मुद्रित किया जाना चाहिए है:
(u'Rt. 613N (Giles County)', u'Big Stony Ck Rd; Rt. 635E/W (Giles County)', u'Cabin Ln; Rocky Mount Rd; Rt. 721E/W (Giles County)', u'Moderate', u'snow or ice', u'01/13/2010 10:50 AM')
किसी भी suggesti इस तरह ऑन या सहायता की सराहना की जाती है, और अग्रिम में धन्यवाद।
आपको धन्यवाद –
आपको इसके लिए सुंदर सूप का उपयोग करने की आवश्यकता नहीं है। आप python3 htmlparser का उपयोग कर सकते हैं: https://github.com/schmijos/html-table-parser-python3/blob/master/html_table_parser/parser.py – schmijos