【发布时间】:2016-08-08 17:51:30
【问题描述】:
我正在尝试从 html 页面中抓取一些简单的字典信息。到目前为止,我能够在 IDE 上打印我需要的所有单词。我的下一步是将单词转移到一个数组中。我的最后一步是将数组保存为 csv 文件......当我运行我的代码时,它似乎在第 1309 个或第 1311 个单词之后停止获取信息,尽管我相信网页上有超过 100 万个。我被困住了,非常感谢任何帮助。谢谢你
from bs4 import BeautifulSoup
from urllib import urlopen
import csv
html = urlopen('http://www.mso.anu.edu.au/~ralph/OPTED/v003/wb1913_a.html').read()
soup = BeautifulSoup(html,"lxml")
words = []
for section in soup.findAll('b'):
words.append(section.renderContents())
print ('success')
print (len(words))
myfile = open('A.csv', 'wb')
wr = csv.writer(myfile)
wr.writerow(words)
【问题讨论】:
标签: python csv web-scraping beautifulsoup