首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取Wikipedia表结果

获取Wikipedia表结果
EN

Stack Overflow用户
提问于 2020-03-31 04:13:02
回答 1查看 31关注 0票数 0

我需要收集两个不同的数组,国家代码顶级域名(例如.ac)和国家(请参阅链接:https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains)。

我尝试获取我需要的信息,如下所示:

代码语言:javascript
复制
import requests
from bs4 import BeautifulSoup as bs
with requests.Session() as s: # use session object for efficiency of tcp re-use
        s.headers = {'User-Agent': 'Mozilla/5.0'}
        r = s.get('https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains')
        soup = bs(r.content, 'lxml')
        # print(soup.prettify)
tld_table=soup.find('table',{'class':'wikitable sortable'})
links=tld_table.findAll('a')

但是当我考虑class: wikitable sortable时,它给了我错误的结果。

你能帮我弄清楚吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-31 04:20:27

代码语言:javascript
复制
import pandas as pd
tables = pd.read_html("https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains")
tables[6] // is the table of the countries
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60938764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档