python - python web-crawler 猜测解析器警告
问题描述
我正在尝试使用 python (3.8) 制作一个网络爬虫,我主要认为我已经完成了,但是我遇到了这个错误,任何人都可以帮助我并提前感谢。
蟒蛇代码:
import requests
from bs4 import BeautifulSoup
def aliexpress_spider (max_pages):
page = 1
while page <= max_pages:
url = "https://www.aliexpress.com/af/ps4.html?trafficChannel=af&d=y&CatId=0&SearchText=ps4<ype=affiliate&SortType=default&page=" + str(page)
sourcecode = requests.get(url)
plaintext = sourcecode.text
soup = BeautifulSoup(plaintext)
for link in soup.findAll('a' , {'class' : 'item-title'}):
href = "https://www.aliexpress.com" + link.get("href")
title = link.string
print(href)
print(title)
page += 1
aliexpress_spider(1)
错误按摩:
GuessedAtParserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.
The code that caused this warning is on line 11 of the file C:/Users/moham/PycharmProjects/moh/test.py. To get rid of this warning, pass the additional argument 'features="html.parser"' to the BeautifulSoup constructor.
soup = BeautifulSoup(plaintext)
解决方案
import requests
from bs4 import BeautifulSoup
def aliexpress_spider (max_pages):
page = 1
while page <= max_pages:
url = "https://www.aliexpress.com/af/ps4.html?trafficChannel=af&d=y&CatId=0&SearchText=ps4<ype=affiliate&SortType=default&page=" + str(page)
sourcecode = requests.get(url)
soup = BeautifulSoup(sourcecode.text ,"html.parser")
for link in soup.findAll('a' , {'class' : 'item-title'}):
href = "https://www.aliexpress.com" + link.get("href")
title = link.string
print(href)
print(title)
print(soup.title)
page += 1
aliexpress_spider(1)
推荐阅读
- java - 如何使用java将对象插入正确的位置?
- security - 如何在 suricata.yml 的 HOME_NET 中定义几个地址?
- c# - 列表未设置值到演示者的控件
- javascript - 使用 pdf.js 在带有加载的 pdf 文件的画布中绘制矩形
- java - 如果客户端在密钥库中有多个证书,将选择哪个 SSL 证书
- kubernetes - Kubenetes Pod 显示状态“已完成”,没有任何作业
- excel - VBA随机函数问题 - 关闭工作文件时不起作用
- java - 如何在 Liferay 7.2 中使用 DynamicQuery 查询 JournalArticle 的最新版本
- javascript - ${} 模板文字(ES2015)在 jsp 页面下工作
- r - 将闪避和堆栈位置与 ggplot2 组合在同一个条形图中