冒险进入Python世界。我上过codeacademy课程,浏览了stack和youtube,但遇到了一个我无法解决的问题。你知道吗
我正试图对维基百科中的一个表进行简单的打印,但在编写自己的代码时失败了,我决定使用一个教程示例进行构建。但是这不起作用,我也不知道为什么。你知道吗
这是包含适当链接的代码。我的最终结果是一个空列表“[]”。我正在使用PyCharm 2017.2、beautifulsoup4.6.0、requests 2.18.4和python3.6.2。谢谢你的建议。作为参考,教程网站是here
import requests
from bs4 import BeautifulSoup
WIKI_URL = "https://en.wikipedia.org/wiki/List_of_volcanoes_by_elevation"
req = requests.get(WIKI_URL)
soup = BeautifulSoup(req.content, 'lxml')
table_classes = {"class": ["sortable", "plainrowheaders"]}
wikitables = soup.findAll("table", table_classes)
print(wikitables)
您可以使用正则表达式来实现这一点。你知道吗
requests.get(WIKI_URL).content
获得网站内容<table>(?P<table>*+?)</table>
)。它所做的是获取<table>
和</table>
标记之间的任何内容。对于使用python的regex来说,这是一个很好的documentation。看看re.findall()
。你知道吗re.findall()
又是关键。你知道吗相关问题 更多 >
编程相关推荐