MCPcopy
hub / github.com/yhangf/PythonCrawler / get_data

Function get_data

spiderFile/get_history_weather.py:7–21  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

5
6
7def get_data(url):
8 html = rq.get(url).content.decode("gbk")
9 soup = BeautifulSoup(html, "html.parser")
10 tr_list = soup.find_all("tr")
11 dates, conditions, temperatures = [], [], []
12 for data in tr_list[1:]:
13 sub_data = data.text.split()
14 dates.append(sub_data[0])
15 conditions.append("".join(sub_data[1:3]))
16 temperatures.append("".join(sub_data[3:6]))
17 _data = pd.DataFrame()
18 _data["日期"] = dates
19 _data["天气状况"] = conditions
20 _data["气温"] = temperatures
21 return _data
22
23# 获取广州市2019年第一季度天气状况
24data_1_month = get_data("http://www.tianqihoubao.com/lishi/guangzhou/month/201901.html")

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected