一段python…
Jump to turn (11)
- 1一段python 代码,从这个网址https://datachart.500.com/dlt/history/history.shtml获取数据大乐透开奖的结果
- 2以markdown的格式显示
- 3一段python 代码,从这个网址https://datachart.500.com/dlt/history/history.shtml获取数据大乐透开奖的结果
- 4代码的标点不正确
- 5把上面代码中的单引号改为英文中的单引号
- 6上面代码不方便复制
- 7把内容放到markdown格式显示
- 8'NoneType' object has no attribute 'findall'
- 9import requests import pandas as pd from bs4 import BeautifulSoup url = 'https:/
- 10你的代码复制下来双引号全部不行
- 11markdown格式
- User
- Assistantpython
import requests import pandas as pd from bs4 import BeautifulSoup url = 'https://datachart.500.com/dlt/history/history.shtml' res = requests.get(url) soup = BeautifulSoup(res.text, 'html.parser') table = soup.find('table', class_='t1') thead = table.find('thead') th_list = [th.text.strip() for th in thead.find_all('th')] tbody = table.find('tbody') tr_list = [] for tr in tbody.find_all('tr'): tr_td = [td.text.strip() for td in tr.find_all('td')] tr_list.append(tr_td) df = pd.DataFrame(tr_list, columns=th_list) print(df)