BeautifulSoup不适用于某些网站 [英] BeautifulSoup does not work for some web sites

查看:82
本文介绍了BeautifulSoup不适用于某些网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个便条纸

import urrlib2
from bs4 import BeautifulSoup
url = "http://www.shoptop.ru/"
page = urllib2.urlopen(url).read()
soup = BeautifulSoup(page)
divs = soup.findAll('a')
print divs

对于网站,它是否打印空列表?可能是什么问题?我在Ubuntu 12.04上运行

For this web site, it prints empty list? What can be problem? I am running on Ubuntu 12.04

推荐答案

实际上,BeautifulSoup中有很多错误,可能会引发一些未知错误.使用lxml解析器

Actually there are quite couple of bugs in BeautifulSoup which might raise some unknown errors. I had a similar issue when working on apache using lxml parser

因此,只需尝试使用文档

soup = BeautifulSoup(page, "html.parser")

这应该有效!

这篇关于BeautifulSoup不适用于某些网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆