Python网页抓取,程序赢得';开始

Python网页抓取,程序赢得';开始,python,pandas,web-scraping,Python,Pandas,Web Scraping,我是一名Java和C#开发人员,目前正在学习Python(特定于web抓取)。当我尝试启动我的脚本时(只需双击它),它不会打开。终端打开几毫秒,然后关闭。我犯了什么错误 将熊猫作为pd导入 将numpy作为np导入 导入请求 从bs4导入BeautifulSoup 产品所有页面=[] 对于范围(1,15)内的i: 响应=请求。获取(“https://www.bol.com/nl/s/?page={i} &searchtext=洗手液+消毒剂&view=列表“) content=response.

我是一名Java和C#开发人员,目前正在学习Python(特定于web抓取)。当我尝试启动我的脚本时(只需双击它),它不会打开。终端打开几毫秒,然后关闭。我犯了什么错误

将熊猫作为pd导入
将numpy作为np导入
导入请求
从bs4导入BeautifulSoup
产品所有页面=[]
对于范围(1,15)内的i:
响应=请求。获取(“https://www.bol.com/nl/s/?page={i} &searchtext=洗手液+消毒剂&view=列表“)
content=response.content
parser=BeautifulSoup(内容为“html.parser”)
body=parser.body
producten=body.find\u all(class=“产品项--行js\u项\u根”)
product\u所有页面。扩展(producten)
len(产品所有页面)
price=float(产品所有页面[1].meta.get('content'))
productname=product\u所有页面[1]。查找(class=“product title--inline”).a.getText()
印刷品(价格)
打印(产品名称)
productlijst=[]
对于产品所有页面中的项目:
如果item.find(class=“product prices”).getText()='\nNet leverbaar\n':
价格=无
其他:
价格=浮动(item.meta['content'])
product=item.find(class=“product title--inline”).a.getText()
productlijst.append([产品,价格])
打印(productlijst[:3])
df=pd.DataFrame(productlijst,列=[“产品”,“价格”])
打印(df.形状)
df[“价格”]。描述()

尝试从命令行运行代码,然后可以看到调试输出。您的代码抛出一个
AttributeError
,因为
content
不包含任何数据。问题是url没有格式化,因为您没有启动f字符串格式化。这应该起作用:

response = requests.get(f"https://www.bol.com/nl/s/?page={i}&searchtext=hand+sanitizer&view=list")

成功了!非常感谢你发现了我的错误。