用requests抓取国美电视商品信息
时间: 2023-09-07 09:14:18 浏览: 48
你可以使用 Python 的 requests 库来抓取国美电视商品信息。首先,你需要导入 requests 库,并发送一个 GET 请求到国美电视商品的网页。然后,你可以使用 Beautiful Soup 或其他 HTML 解析库来解析网页内容,提取所需的商品信息。
以下是一个示例代码,演示如何使用 requests 和 Beautiful Soup 抓取国美电视商品信息:
```python
import requests
from bs4 import BeautifulSoup
# 发送 GET 请求
url = "https://search.gome.com.cn/search?question=电视"
response = requests.get(url)
# 解析网页内容
soup = BeautifulSoup(response.text, "html.parser")
# 提取商品信息
products = soup.find_all("div", class_="item-wrap")
for product in products:
title = product.find("a", class_="item-link").text.strip()
price = product.find("span", class_="price").text.strip()
print("商品名称: ", title)
print("商品价格: ", price)
print("-----------------------")
```
请注意,这只是一个简单的示例代码,你可能需要根据具体网页结构进行适当的调整和修改。另外,为了避免被网站屏蔽或违反网站的使用条款,请确保你的抓取行为合法,并且尊重网站的访问频率限制。