我正在完成“自动处理无聊的东西”的网页抓取部分,在尝试使用BeautifulSoup
时出现以下错误
UserWarning: The soupsieve package is not installed. CSS selectors cannot be used.
我运行了pip install beautifulsoup4
和pip install soupsieve
。导致错误的行是:
我到处找了一下,没有找到解决办法。任何帮助都将不胜感激。在
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()
目前没有回答
相关问题 更多 >
编程相关推荐