我最近在Windows机上将BeautifulSoup从3.0版升级到4.1版。
我现在收到一个奇怪的错误:
File "C:\path\to\myscript.py", line 23
0, in soupify
return BeautifulSoup(html, convertEntities=BeautifulSoup.HTML_ENTITIES)
AttributeError: type object 'BeautifulSoup' has no attribute 'HTML_ENTITIES'
下面是导致抛出异常的代码片段:
奇怪的是,有时BeautifulSoup对象确实会提供所需的数据,但有时我会得到一个错误,比如listindex error、out of range或nonetype object does not have attribute findNext(),这是嵌套在其他元素中的数据。
这是代码:
url = 'http://www.computerstore.nl/product/470130/category-208983/asrock-z97-extreme6.html'
source_code = requests.get(url)
plain_text = source_
我试图执行以下python代码
import httplib2
from BeautifulSoup import BeautifulSoup, SoupStrainer
http = httplib2.Http()
status, response = http.request('http://www.nytimes.com')
for link in BeautifulSoup(response, parseOnlyThese=SoupStrainer('a')):
if link.has_attr('href'):
from bs4 import BeautifulSoup
import requests
import time
urls = ['http://www.soku.com/search_playlist/q_python_orderby_1_limitdate_0?site=14&page={}&spm=a2h0k.8191403.0.00'.format(str(i)) for i in range(1,30,1)]
def UUrl(urls):
def Url(url):
single_urls = []
t
在python和BeatifulSoup的帮助下,我从一个网站得到了一篇文字文章。现在我有个奇怪的问题..。我只是在多个p标记中打印出文本,这些标记位于带有类dr_article的div中。下面的with代码如下所示:
from bs4 import BeautifulSoup
def getArticleText(webtext):
soup = BeautifulSoup(webtext)
divTag = soup.find_all("div", {"class":"dr_article"})
for tag in divTag:
我正在尝试使用Python和BeautifulSoup访问某些td标签中的内容。我可以获得满足条件的第一个td标记(使用find),也可以获取所有的td标记(使用findAll)。
现在,我可以只使用findAll,获取所有内容,并从中获取我想要的内容,但这似乎效率很低(即使我对搜索进行了限制)。有没有办法转到满足我想要的条件的某个td标签?比如说第三个,还是第十个?
到目前为止,我的代码如下:
from __future__ import division
from __future__ import unicode_literals
from __future__ import print
我最近在玩美人汤的时候遇到了一个关于python字典的奇怪问题。我的代码如下所示。
import urllib2
from BeautifulSoup import BeautifulSoup
response = urllib2.urlopen("http://www.msn.com")
html = response.read()
soup = BeautifulSoup(html)
anchors = soup.findAll('a')
for a in anchors:
if not a.has_key('href') == &
我正在尝试抓取这里的网站:。使用如下代码:
from bs4 import BeautifulSoup
import urllib.request
html = urllib.request.urlopen("ftp://ftp.sec.gov/edgar/daily-index/")
soup = BeautifulSoup(line, "lxml")
soup.a # or soup.find_all('a') neither of them works
#return None.
请帮帮忙,我真的很沮丧。我怀疑是标签导致了问题。站点的超
我试图用BeautifulSoup从一个特定的站点(谷歌学者)抓取具有相同标签的所有对象,但它不会在页面末尾的“显示更多”下删除该对象。我怎么才能修复它?
下面是我的代码示例:
# -*- coding: cp1253 -*-
from urllib import urlopen
from bs4 import BeautifulSoup
webpage=urlopen('http://scholar.google.gr/citations?user=FwuKA4UAAAAJ&hl=el')
soup=BeautifulSoup(webpage)
for t in so
我已经使用Add/Remove Software GUI工具在Fedora16(64位)上安装了BeautifulSoup for Python3 (python3-BeautifulSoup-1:3.2.0-4.fc16)。它似乎已正确安装(yum info python3-BeautifulSoup显示'Repo: Installed'),但当我尝试在交互式外壳中导入模块(使用导入BeautifulSoup语句)时,我收到一条'ImportError: No BeautifulSoup named BeautifulSoup‘消息。
我还安装了Python2的Bea
我正在解析一些html表单与美丽的汤。基本上我有大约60个输入框,大部分是单选按钮和复选框。到目前为止,这可以使用以下代码:
from BeautifulSoup import BeautifulSoup
x = open('myfile.html','r').read()
out = open('outfile.csv','w')
soup = BeautifulSoup(x)
values = soup.findAll('input',checked="checked")
# echoes so
我认为这将是有趣和有趣的分享。我遇到了一个我从来没有遇到过的奇怪的情况。
我在和蟒蛇喝可口的汤。在抓取之后,我在HTML末尾得到了最奇怪的输出。
谁能告诉我这是否是亚马逊的开发者故意的?或者这是其他的东西?
仅供参考这里是我用来显示它与我无关的代码
import lxml
from bs4 import BeautifulSoup
import urllib.request as re
# ********Below is the soup used to gather the HTML************
url = "https://www.amazon.
我在python中创建了一个脚本来解析不同机构的website address,从它的登陆页面和从它的内部页面解析location address。我无法理解的是,如何同时返回string和list,以便在另一个函数中重用它们。更清楚的是:我希望从website address函数返回list of links和collect_links()函数,并在get_info()函数中重用它们。我的当前方法引发了一个错误- ValueError: not enough values to unpack (expected 2, got 1)。
到目前为止这是我的尝试:
import re
import
我在BeautifulSoup中看到了一些奇怪的行为,如下面的示例所示。
import re
from bs4 import BeautifulSoup
html = """<p style='color: red;'>This has a <b>color</b> of red. Because it likes the color red</p>
<p class='blue'>This paragraph has a color of blue.</p>
<
我看过一段视频,教我如何使用BeautifulSoup和请求刮一个网站,这是代码
from bs4 import BeautifulSoup as bs4
import requests
import pandas as pd
pages_to_scrape = 1
for i in range(1,pages_to_scrape+1):
url = ('http://books.toscrape.com/catalogue/page-{}.html').format(i)
pages.append(url)
for item in pages:
p