2017-06-29 29 views
1

我试图用美丽的汤提取<tr>没有class和id

<tr class="TTRow"> 
     <td> 
     <a class="tablebluelink" href="" target="_blank">517330</a></td> 
     <td class="TTRow_left">CMI</td> 
     <td>29 Jun 2017</td> 
    </tr> 

我想提取从下面的HTML日期标签数据这将工作

r=urllib.urlopen('http://www.bseindia.com/corporates/Forth_Results.aspx?expandable=0').read() 
soup=BeautifulSoup(r) 
companies= soup.findAll("tr", class_= "TTRow") 
i=0 
for company in companies: 
    upcoming_company_results[i]=str(company.find("td",class_="TTRow_left").text) 
    date[i]=str(company.find("td").text) 
    i=i+1 

但它给带班的文本= “tablbluelink”为日期[i]而不是日期。 如何提取日期“2017年6月29日”形式。

+0

我找到了解决办法和利用的内容,如果你是某个地方卡住这样的参考,HTTPS://www.crummy。 COM /软件/ BeautifulSoup/BS3/documentation.html上#内容 –

回答

0

我利用的内容,请使用这个答案更好的参考Python BeautifulSoup extract text between element

for company in companies: 
    upcoming_company_results[i]=str(company.find("td",class_="TTRow_left").text) 
    date[i]= str(company.contents[3].text) 
    i=i+1