未安装Soupsieve包|自动执行钻孔stu

2024-05-02 22:19:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在完成“自动处理无聊的东西”的网页抓取部分,在尝试使用BeautifulSoup时出现以下错误

UserWarning: The soupsieve package is not installed. CSS selectors cannot be used.

我运行了pip install beautifulsoup4pip install soupsieve。导致错误的行是:

^{pr2}$

我到处找了一下,没有找到解决办法。任何帮助都将不胜感激。在

import requests, os, bs4

url = 'http://xkcd.com'
os.makedirs('xkcd')
while not url.endswith('#'):
    print('Downloading page %s...' % url)
    res = requests.get(url)
    res.raise_for_status()

soup = bs4.BeautifulSoup(res.text, features="html.parser")
comicElem = soup.select('#comic img')
if comicElem == []:
    print('Could not find the comic image.')
else:
    comicUrl = 'http:' + comicElem[0].get('src')
#Download the image
    print('Downloading image %s...' % (comicUrl))
    res = requests.get(comicUrl)
    res.raise_for_status()

Tags: installpipimageurlgetos错误not