本帖最后由 qiuyouzhi 于 2020-4-1 18:01 编辑
齐紫荆。 发表于 2020-4-1 17:44
>>> table = soup.find('table',class_="wikitable").children
>>> for tr in table:
if isinstance(t ...
顺便给你包装了一下:from requests import get
from bs4 import BeautifulSoup as BS
def open_url(url):
# 可以加headers
res = get(url)
return res
def get_Info(res):
soup = BS(res.text, "html.parser")
table = soup.find('table').children
i = 0 # 它用于判断何时该换行
for tr in list(table)[1]:
if i == 2:
print()
i = 0
print(tr.string.strip(), end = '') # strip()删除空格
i += 1
def main():
url = "https://yanyu.huijiwiki.com/wiki/伙伴成长以及加点属性排行一览"
get_Info(open_url(url))
if __name__ == "__main__":
main()
|