Python学习之爬虫简单例子
* =COUNTIF(BET!A:A,A2))
* =COUNTIFS(BET!A:A,A2,BET!G:G,"赢")
* =COUNTIFS(BET!A:A,A2,BET!G:G,"输")
* =SUMIF(BET!A:A,B2,BET!J:J)-SUMIF(BET!A:A,B2,BET!I:I)
* =352 + SUM(F:F)
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")
def import_data():
header = [
"球队",
"赛",
"进球",
"失球",
"场均进球(GS)",
"场均失球(GA)"
]
rows = [
]
for i in range(1000):
#row = [team_name, team_round , team_gs, team_ga, team_avg_gs, team_avg_ga]
rows.append(row)
pd.DataFrame(rows, columns=header, index=False)