专业做网站登录,学做美食去哪个网站好,永久不收费的软件app,购物商城平台开发在运行代码之前#xff0c;需要到微软商店下载安装python环境#xff0c;35m#xff0c;都是自动的。
1、安装python 的extensions插件。 ctrlshiftx 输入 python 后点击 install 按钮。
2、新建文件夹spider文件夹。
3、在新建文件夹spider下新建文件spider.py源代码。…在运行代码之前需要到微软商店下载安装python环境35m都是自动的。
1、安装python 的extensions插件。 ctrlshiftx 输入 python 后点击 install 按钮。
2、新建文件夹spider文件夹。
3、在新建文件夹spider下新建文件spider.py源代码。 4、遇到问题升级pip执行文件。
pip install request
报如下错误
WARNING: Retrying (Retry(total4, connectNone, readNone, redirectNone, statusNone)) after connection broken by SSLError(SSLEOFError(8, EOF occurred in violation of protocol (_ssl.c:997))): /simple/request/
WARNING: Retrying (Retry(total3, connectNone, readNone, redirectNone, statusNone)) after connection broken by SSLError(SSLEOFError(8, EOF occurred in violation of protocol (_ssl.c:997))): /simple/request/
ERROR: Could not find a version that satisfies the requirement request (from versions: none)
ERROR: No matching distribution found for request
解决
C:\Users\zhang\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\python.exe -m pip install --upgrade pip
5、遇到问题pip命令行修改。
再次
pip install request
报如下错误
ERROR: Could not find a version that satisfies the requirement request (from versions: none) ERROR: No matching distribution found for request
解决
转换下载地址douban
pip install request-i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
接着报错
ERROR: Cannot unpack file C:\Users\zhang\AppData\Local\Temp\pip-unpack-2ejahzt3\simple.html (downloaded from C:\Users\zhang\AppData\Local\Temp\pip-req-build-xfd621gj, content-type: text/html); cannot detect archive format ERROR: Cannot determine archive format of C:\Users\zhang\AppData\Local\Temp\pip-req-build-xfd621gj
解决换成清华的网址改写requests【加s】
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn requests
按照以上方法分别安装bs4openpyxl模块
6、按运行按钮执行或者在控制台程序中输入命令
python spider.py
最后发现一切的原因来自于requests 少打了一个s字母。
以下是chatgpt写的爬虫代码
import requests
from bs4 import BeautifulSoup
import openpyxl# Make the request and parse the HTML content
url https://books.toscrape.com/
response requests.get(url)
soup BeautifulSoup(response.text, html.parser)# Extract the book data
books []
for article in soup.find_all(article):book {}book[title] article.h3.a[title]book[price] article.select_one(.price_color).get_text(stripTrue)books.append(book)# Save the book data to an Excel file
wb openpyxl.Workbook()
sheet wb.active
sheet.append([Title, Price])
for book in books:sheet.append([book[title], book[price]])
wb.save(books.xlsx)网址All products | Books to Scrape - Sandbox
结果