我试图从网页中获取数据,而我想要的所有文本都放在<p class="heading2">
和More...
之间。你知道吗
它适用于第一批文本,但只适用于那一批。你知道吗
例如,我得到:
Info about grant 1
但在网站上有:
Info about grant 1
Info about grant 2
Info about grant 3
etc.
这是我正在使用的代码。我是新来的,希望有人能帮我!你知道吗
from bs4 import BeautifulSoup
import sheetsync
import urllib2, csv
url = urllib2.urlopen('http://www.asanet.org/funding/funding_and_grants.cfm').read()
def processData():
url = urllib2.urlopen('http://www.asanet.org/funding/funding_and_grants.cfm').read()
soup = BeautifulSoup(url)
metaData = soup.find_all("div", {"id":"memberscontent"})
authors = []
for html in metaData:
text = BeautifulSoup(str(html).strip()).encode("utf-8").replace("Deadline", "DEADLINE").replace('\s+',' ').replace('\n+',' ').replace('\s+',' ')
authors.append(text.split('<p class="heading2">')[1].split('More...')[0].strip()) # get Pos
txt = 'grants.txt'
with open(txt, 'ab') as out:
out.writelines(authors)
processData()
我将依赖于
heading2
并获得下两个p
标记siblings:第一个是截止日期,第二个是grant的文本:印刷品:
相关问题 更多 >
编程相关推荐