【发布时间】:2017-12-17 06:05:36
【问题描述】:
我正在尝试用数字解析 'https://projecteuler.net/problem=8' 的中间位。由于它没有单独的类来选择它,所以我使用了
r = requests.get('https://projecteuler.net/problem=8')
data = r.text
soup = BeautifulSoup(data, "lxml")
[para1, para2, para3] = (soup.find_all('p'))
分隔段落,但这会留下很多额外的垃圾(<p> and <br>)。有没有清除所有这些的命令?有没有比我目前使用的更好的分割命令?从来没有真正用 Python 做过很多网络爬虫...
【问题讨论】:
-
文档类型为
html,您可能希望使用'html.parser'而不是"lxml"。另外,一旦你有了那张数字表,你理想的输出是什么? (NumPy 数组,还是只想打印块?)
标签: python html beautifulsoup lxml