Regex, APIs, BeautifulSoup: python import requests, re from pprint import pprint from bs4 import BeautifulSoup complete the missing bodies of the functions below: def companies(website): """
Regex, APIs, BeautifulSoup: python
import requests, re
from pprint import pprint
from bs4 import BeautifulSoup
complete the missing bodies of the functions below:
"""
Question 6
- Acces the table at the provided website:
'https://en.wikipedia.org/wiki/Companies_listed_on_the_New_York_Stock_Exchange_(C)'
- Parse through it and retrieve the names of all companies in the site that
~ Are based in the US
~ Have an acronym anywhere in their name
~ (Let us define 'acronym' as any two or more consecutive capital letters)
Args:
string (website)
Returns:
list (list of company names)
>>> web1 =
'https://en.wikipedia.org/wiki/Companies_listed_on_the_New_York_Stock_Exchange_(C)'
>>> web2 =
'https://en.wikipedia.org/wiki/Companies_listed_on_the_New_York_Stock_Exchange_(T)'
>>> companies(web1)
['CACI',
'CAI International, Inc.',
'CARBO Ceramics Inc.',
...
'CYS Investments, Inc.']
>>> len(companies(web1))
>>> len(companies(web2))
23
"""
pass
test code:
'https://en.wikipedia.org/wiki/Companies_listed_on_the_New_York_Stock_Exchange_(C)'
# web2 =
# pprint(companies(web1))
# pprint(companies(web2))

# def companies(website):
# # Acces the table at the provided website:
# # 'https://en.wikipedia.org/wiki/Companies_listed_on_the_New_York_Stock_Exchange_(C)'
# # Parse through it and retrieve the names of all companies in the site that
# # ~ Are based in the US
# # ~ Have an acronym anywhere in their name
# # ~ (Let us define 'acronym' as any two or more consecutive capital letters)
# # Args:
# # string (website)
# # Returns:
# # list (list of company names)
# # >>> web1 =
# # 'https://en.wikipedia.org/wiki/Companies_listed_on_the_New_York_Stock_Exchange_(C)'
# # >>> web2 =
# # 'https://en.wikipedia.org/wiki/Companies_listed_on_the_New_York_Stock_Exchange_(T)'
# # >>> companies(web1)
# #
Trending now
This is a popular solution!
Step by step
Solved in 2 steps









