用python爬取http://124.95.133.164/work/xjlp/new_building.jsp
时间: 2023-10-08 11:08:30 浏览: 62
好的,您想要用Python爬取http://124.95.133.164/work/xjlp/new_building.jsp这个网页的内容是吗?使用Python进行爬虫可以使用第三方库requests和BeautifulSoup来实现。首先需要安装这两个库,可以使用以下命令进行安装:
```
pip install requests
pip install beautifulsoup4
```
接着,可以使用以下代码获取网页内容并解析:
```python
import requests
from bs4 import BeautifulSoup
url = "http://124.95.133.164/work/xjlp/new_building.jsp"
response = requests.get(url)
html = response.content.decode('utf-8')
soup = BeautifulSoup(html, 'html.parser')
print(soup.prettify())
```
这段代码首先使用requests库获取网页内容,然后使用BeautifulSoup把HTML代码解析为可读性更高的形式。通过print(soup.prettify())可以输出整个网页的HTML代码。
相关问题
用python爬取http://124.95.133.164/work/xjlp/new_building.jsp最里层数据
为了爬取 http://124.95.133.164/work/xjlp/new_building.jsp 中的最里层数据,你可以使用 Python 的 requests 和 BeautifulSoup 库。
以下是一个简单的示例代码,可以获取页面中的表格数据:
```python
import requests
from bs4 import BeautifulSoup
url = "http://124.95.133.164/work/xjlp/new_building.jsp"
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")
table = soup.find_all("table")[2] # 获取第三个表格
for row in table.find_all("tr")[1:]:
cells = row.find_all("td")
if cells:
print([cell.get_text(strip=True) for cell in cells])
```
这个代码会输出表格中每一行的数据。你可以根据自己的需求调整代码,以获取你所需要的数据。
用python爬取网页http://124.95.133.164/work/xjlp/new_building.jsp到表格
好的,可以使用Python中的requests和BeautifulSoup库来实现网页爬取和数据提取。以下是一个简单的示例代码:
```python
import requests
from bs4 import BeautifulSoup
import pandas as pd
# 发送GET请求并获取网页内容
url = 'http://124.95.133.164/work/xjlp/new_building.jsp'
response = requests.get(url)
html = response.content
# 使用BeautifulSoup解析网页内容并提取表格数据
soup = BeautifulSoup(html, 'html.parser')
table = soup.find('table', {'class': '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)
# 将数据保存到DataFrame中并输出到控制台
df = pd.DataFrame(data)
print(df)
```
这段代码会将从网页中提取的表格数据保存到一个DataFrame中,并输出到控制台。你可以根据需要对输出格式进行调整。