概述
from bs4 import BeautifulSoup
import requests
r = requests.get('https://en.wikipedia.org/wiki/List_of_municipalities_in_Massachusetts')
soup = BeautifulSoup(r.text, 'lxml')
rows = soup.find(class_="wikitable sortable").find_all('tr')[1:]
for row in rows:
cell = [i.text for i in row.find_all('td')]
print(cell)
输出:['Abington', 'Town', 'Plymouth', 'Open town meeting', '15,985', '1712']
['Acton', 'Town', 'Middlesex', 'Open town meeting', '21,924', '1735']
['Acushnet', 'Town', 'Bristol', 'Open town meeting', '10,303', '1860']
['Adams', 'Town', 'Berkshire', 'Representative town meeting', '8,485', '1778']</
最后
以上就是落后白开水为你收集整理的python中bs4.element.tag_BeautifulSoup标记是bs4.element.NavigableString和bs4.element.tag类型的全部内容,希望文章能够帮你解决python中bs4.element.tag_BeautifulSoup标记是bs4.element.NavigableString和bs4.element.tag类型所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复