酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

用python 写一个爬虫脚本,主要是爬取http://ggzyjy.zibo.gov.cn:8082/jyxx/002002/gonggongziyuan.html,这个地址中所有的项目信息,项目信息包括项目发生地址,项目名称,项目发布时间,并导出到对应的excel中

```python import requests from bs4 import BeautifulSoup import pandas as pd url = "http://ggzyjy.zibo.gov.cn:8082/jyxx/002002/gonggongziyuan.html" response = requests.get(url) response.encoding = 'utf-8' soup = BeautifulSoup(response.text, 'html.parser') project_list = [] table = soup.find('table', {'class': 'ewb-list'}) rows = table.find_all('tr') for row in rows[1:]: columns = row.find_all('td') project_name = columns[1].text.strip() project_address = columns[2].text.strip() publish_time = columns[3].text.strip() project_list.append([project_name, project_address, publish_time]) df = pd.DataFrame(project_list, columns=['项目名称', '项目发生地址', '项目发布时间']) df.to_excel('项目信息.xlsx', index=False) ``` [2024-07-15 17:29:48 | AI写代码神器 | 266点数解答]

相关提问