import BeautifulSoup
import pandas as pd
import urllib.request, urllib.error
def requestUrl(url):
headers = {
'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36",
}
request = urllib.request.Request(url, headers= headers)
html=""
try:
response = urllib.request.urlopen(request)
html = response.read().decode("utf-8")
except urllib.error.URLError as e:
if hasattr(e, "reason"):
print(e.reason)
if hasattr(e, "code"):
print(e.code)
return html
def getData(requestData):
pass
soup = BeautifulSoup(requestData, "html.parser")
tbls = soup.find_all("div", id="league_table")
print(tbls)
def main():
url = "网页地址"
html = requestUrl(url)
getData(html)
if __name__ == "__main__":
main()
print("execute over")