抓取国家电⽹电⼦商务平台所有招标公告,下载“项⽬公告⽂件” 将下载的项⽬公告⽂件解压后,寻找有'货物清单'字样的Excel表格, 将所有的货物清单统⼀合并成⼀个csv⽂件 获取货物清单Excel表格中的指定共15列数据 '包号', '⽹省采购申请⾏号', '项⽬单位', '需求单位', '项⽬名称', '⼯程电压等级', '物资名称', '物资描 述','单位', '数量', '交货⽇期', '交货地点', '备注', '技术规范ID', '状态' 其中'状态'列是后期添加列,指的是本标书的项⽬状态,例如'已经截标','正在评标','评标结束'等 状态
时间: 2023-12-23 13:05:04 浏览: 32
好的,我明白了您的要求。您需要抓取国家电网电子商务平台所有招标公告,并下载其中的“项目公告文件”解压后,寻找有“货物清单”字样的Excel表格,将所有的货物清单统一合并成一个csv文件。同时,您需要获取货物清单Excel表格中的指定共15列数据,分别是:'包号', '网省采购申请行号', '项目单位', '需求单位', '项目名称', '工程电压等级', '物资名称', '物资描述','单位', '数量', '交货日期', '交货地点', '备注', '技术规范ID', '状态',其中'状态'列是后期添加列,指的是本标书的项目状态,例如'已经截标','正在评标','评标结束'等状态。请问您还有其他要求吗?
相关问题
抓取国家电网电子商务平台所有招标公告,下载项目公告文件,代码示例
抓取国家电网电子商务平台所有招标公告并下载项目公告文件可以使用 Python 网络爬虫实现。以下是一个简单的示例代码:
```python
import requests
from bs4 import BeautifulSoup
import os
# 设置请求头
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
# 获取页面内容的函数
def get_html(url):
response = requests.get(url, headers=headers)
response.encoding = 'utf-8'
html = response.text
return html
# 获取所有招标公告的链接
def get_links():
links = []
for page in range(1, 3): # 暂时只爬前两页
url = f'http://ecp.sgcc.com.cn/ecp2.0/ecp/search/notice.jsp?page={page}¬ice_type=2'
html = get_html(url)
soup = BeautifulSoup(html, 'html.parser')
notices = soup.select('.m_m_c_list tr')
for notice in notices:
link = notice.select_one('a')['href']
links.append(link)
return links
# 下载项目公告文件
def download_files():
links = get_links()
for link in links:
url = f'http://ecp.sgcc.com.cn{link}'
html = get_html(url)
soup = BeautifulSoup(html, 'html.parser')
title = soup.select_one('.detail_tit').get_text()
file_links = soup.select('.m2 a')
for file_link in file_links:
file_url = f'http://ecp.sgcc.com.cn{file_link["href"]}'
file_name = file_link.get_text()
# 创建文件夹
if not os.path.exists(title):
os.makedirs(title)
# 下载文件
with open(f'{title}/{file_name}', 'wb') as f:
f.write(requests.get(file_url).content)
if __name__ == '__main__':
download_files()
```
这个示例代码使用了 requests 库和 BeautifulSoup 库,分别用于发送网络请求和解析 HTML 页面。首先使用 get_links 函数获取所有招标公告的链接,然后遍历每个链接,使用 download_files 函数下载项目公告文件。在下载文件之前,需要先创建相应的目录。
使用简便方法抓取国家电网电子商务平台所有招标公告,代码示例
以下是使用Python简单的方法抓取国家电网电子商务平台所有招标公告的示例代码:
```python
import requests
from bs4 import BeautifulSoup
# 定义要抓取的网站链接
url = 'http://ecp.sgcc.com.cn/html/project/001001001/1.html'
# 发送HTTP请求
response = requests.get(url)
# 解析HTML代码
soup = BeautifulSoup(response.text, 'html.parser')
# 获取总页数
total_page = soup.find_all('a', {'class': 'end'})[0]['href'].split('/')[-1].split('.')[0]
# 遍历所有招标页面
for page in range(1, int(total_page) + 1):
# 构建每一页的链接
page_url = 'http://ecp.sgcc.com.cn/html/project/001001001/{}.html'.format(page)
# 发送HTTP请求
response = requests.get(page_url)
# 解析HTML代码
soup = BeautifulSoup(response.text, 'html.parser')
# 获取所有招标公告的链接
links = soup.find_all('a', {'class': 'a1'})
# 遍历所有链接并输出
for link in links:
print(link['href'])
```
在这段代码中,我们首先定义了要抓取的网站链接,然后发送HTTP请求,并使用BeautifulSoup解析HTML代码。接着,我们获取了该网站所有招标公告的总页数,并使用循环遍历所有招标页面。在每一个页面中,我们获取了所有招标公告的链接,并遍历输出。
需要注意的是,由于国家电网电子商务平台可能会设置反爬机制,因此在实现中需要加入一些技术手段,例如随机化访问时间、使用代理IP等。另外,我们也需要遵守网站的使用规定,避免对网站造成不必要的压力。
相关推荐
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)