草庐IT

beautifulSoup

全部标签

网站的Python正确编码(Beautiful Soup)

我正在尝试加载html页面并输出文本,即使我正确获取网页,BeautifulSoup以某种方式破坏了编码。来源:#-*-coding:utf-8-*-importrequestsfromBeautifulSoupimportBeautifulSoupurl="http://www.columbia.edu/~fdc/utf8/"r=requests.get(url)encodedText=r.text.encode("utf-8")soup=BeautifulSoup(encodedText)text=str(soup.findAll(text=True))printtext.deco

带有 "lxml"解析器的 Python BeautifulSoup 将长字符串分解为字符

这个问题在这里已经有了答案:BeautifulSoupreturnunexpectedextraspaces(3个答案)关闭3年前。我注意到Python[3.6.5]BeautifulSoup[4.6.0]与“lxml”[4.2.1]解析器处理长bytes对象与长字符串的方式之间存在奇怪的不一致。(显然,“long”是>16,384=2**14个字符或字节。)例如,我从麻省理工学院网站下载黑白棋的文本,并以原始(字节)形式和解码为字符串后的形式将其提供给BS。两个对象的长度相同,因为文档中没有多字节字符。frombs4importBeautifulSoupimporturlliburl

python - 防止 BeautifulSoup 将我的 XML 标签转换为小写

我正在使用BeautifulStoneSoup来解析XML文档并更改一些属性。我注意到它会自动将所有XML标记转换为小写。例如,我的源文件有BeautifulSoup转换为的元素.这似乎会引起问题,因为我将修改后的XML文档提供给的程序似乎不接受小写版本。有没有办法在BeautifulSoup中防止这种行为? 最佳答案 不,这不是内置选项。不过,来源非常简单。看起来您想更改Tag.__str__.中encodedName的值 关于python-防止BeautifulSoup将我的XML标

python - 正则表达式匹配错误

我是Python的新手(我也没有接受过任何编程培训),所以在我提问时请记住这一点。我正在尝试搜索检索到的网页并使用指定模式查找所有链接。我已在其他脚本中成功完成此操作,但出现错误raiseerror,v#invalidexpressionsre_constants.error:multiplerepeat我不得不承认我不知道为什么,但我又是Python和正则表达式的新手。但是,即使我不使用模式并使用特定链接(只是为了测试匹配),我也不相信我会返回任何匹配项(当我打印match.group(0)时没有任何内容发送到窗口。链接我测试在下面被注释掉了。有什么想法吗?通过示例学习通常对我来说更

python - Web Scraping Rap lyrics on Rap Genius w/Python

我有点像一个编码新手,我一直在努力从说唱天才身上抓取Andre3000的歌词,http://genius.com/artists/Andre-3000,通过使用BeautifulSoup(一个用于从HTML和XML文件中提取数据的Python库)。我的最终目标是以字符串格式获取数据。这是我目前所拥有的:frombs4importBeautifulSoupfromurllib2importurlopenartist_url="http://rapgenius.com/artists/Andre-3000"defget_song_links(url):html=urlopen(url).r

python - 来自 os.mkdir 的 "No such file or directory"

在一个python项目上工作,它所做的是查看lifehacker.com的索引,然后找到所有带有“headlineh5hover-highlightentry-title”类的标签,然后为每个目录创建文件。但唯一的问题是当我运行它时,我得到OSError:[Errno2]Nosuchfileordirectory:"/home/root/python/TheSonySmartwatch3:ARunner'sPerspective(Updated:1/5/2015)"帮助会很好,谢谢!这是我的自动取款机代码:importreimportosimporturllib2frombs4impo

python - 如何解决 AttributeError : 'NoneType' object has no attribute 'encode' in python

forcomment_entryincomment_feed.entry:content=comment_entry.ToString()parse=BeautifulSoup(content)forconinparse.find('ns0:content'):printcon.strings=con.stringfile.write(s.encode('utf8'))我得到的错误:File"channel_search.py",line108,inyoutube_searchfile.write(s.encode('utf8'))AttributeError:'NoneType'ob

python - BeautifulSoup 导入错误

我正在尝试编写一个简单的本地python脚本来进行一些html解析。我安装了beautifulsoup4并使用导入了它frombs4importBeautifulSoup但是我得到了错误:Traceback(mostrecentcalllast):File"scrape_descriptions.py",line1,infrombs4importBeautifulSoupImportError:Nomodulenamed'bs4'我几乎尝试过以各种方式安装BS4。我先做了sudopipinstallBeautifulSoup4然后我尝试从网站下载实际文件并运行sudopythonset

python - 使用 Beautiful Soup 在 python 中解析网页

我在从网站获取数据时遇到了一些麻烦。网站来源在这里:view-source:http://release24.pl/wpis/23714/%22La+mer+a+boire%22+%282011%29+FRENCH.DVDRip.XviD-AYMO有这样的东西:INFORMACJEOFILMIETytuł............................................:LameràboireOcena.............................................:IMDB-6.3/10(24)Produkcja............

python - 如何使用 BeautifulSoup 访问带命名空间的 XML 元素?

我有一个XML文档,内容如下:40000我的问题是如何使用python中的BeautifulSoup等库访问它们?xmlDom.web["Web"].总计?不起作用? 最佳答案 BeautifulSoup本身不是DOM库(它不实现DOMAPI)。使事情变得更复杂的是,您在该xml片段中使用了namespace。要解析特定的XML片段,您可以按如下方式使用BeautifulSoup:fromBeautifulSoupimportBeautifulSoupxml="""40000"""doc=BeautifulSoup(xml)prin