【发布时间】:2016-04-28 20:14:53
【问题描述】:
我正在使用 lxml.html 模块
from lxml import html
page = html.parse('http://directory.ccnecommunity.org/reports/rptAccreditedPrograms_New.asp?sort=institution')
# print(page.content)
unis = page.xpath('//tr/td[@valign="top" and @style="width: 50%;padding-right:15px"]/h3/text()')
print(unis.__len__())
with open('workfile.txt', 'w') as f:
for uni in unis:
f.write(uni + '\n')
这里的网站 (http://directory.ccnecommunity.org/reports/rptAccreditedPrograms_New.asp?sort=institution#Z) 到处都是大学。
问题在于它解析到字母“H”(244 unis)。 我不明白为什么,因为我看到它解析所有的 HTML 直到最后。
我还记录了我自己,244 不是列表的限制或 python3 中的任何内容。
【问题讨论】:
-
考虑使用
requests和beautifulsoup4? -
同样,正如我所说,它解析 HTML 直到最后。所以问题不在于我使用的请求函数。
标签: python python-3.x web-scraping web-crawler