爬取千里马招标网站招标信息并存到表格
时间: 2024-06-09 18:07:59 浏览: 4
可以使用 Python 的 requests 库和 BeautifulSoup 库来爬取网页信息,并使用 pandas 库来存储到表格中。
以下是一个示例代码:
```python
import requests
from bs4 import BeautifulSoup
import pandas as pd
# 请求目标网页
url = 'http://www.qianlima.com/zb/'
response = requests.get(url)
# 解析网页内容
soup = BeautifulSoup(response.content, 'html.parser')
table = soup.find('table', {'class': 'ztb-table'})
rows = table.find_all('tr')
# 提取表格数据
data = []
for row in rows:
cols = row.find_all('td')
cols = [col.text.strip() for col in cols]
data.append(cols)
# 存储到表格中
df = pd.DataFrame(data[1:], columns=data[0])
df.to_excel('qianlima_zhaobiao.xlsx', index=False)
```
该代码将爬取千里马招标网站首页的招标信息表格,提取其中的数据,存储到名为 `qianlima_zhaobiao.xlsx` 的 Excel 表格中。可以根据实际需求进行修改。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)