草庐IT

BeautifulSoup4

全部标签

python - 如何使用 BeautifulSoup 和 Python 从 <div> 标签内的 <a href> 标签获取信息?

全部。我有一个关于BeautifulSoupwithPython的快速问题。我有几段HTML看起来像这样(唯一的区别是链接和产品名称),我正在尝试从“href”属性获取链接。94.36CAPRISUN-JUICEDRINK-COOLERSVARIETYPACK6OZ40CT我目前有这段Python代码:productLinks=soup.findAll('a',attrs={'class':'on'})forlinkinproductLinks:printlink['href']这有效(对于页面上的每个链接,我都会得到类似/Products/ProductInfoDisplay.asp

python - 使用 python 和 BeautifulSoup 从 html 中提取表格内容

我想从html文档中提取某些信息。例如。它包含一个表(在具有其他内容的其他表格中)像这样:Advisory:RHBA-2013:0947-1Type:BugFixAdvisorySeverity:N/AIssuedon:2013-06-13Lastupdatedon:2013-06-13AffectedProducts:RedHatEnterpriseLinuxELS(v.4)我想提取诸如“Issuedon:”之类的信息。看起来像BeautifulSoup4可以很容易地做到这一点,但不知何故我无法做到正确。到目前为止我的代码:frombs4importBeautifulSoupsoup

python - 使用 BeautifulSoup 提取 &lt;script&gt; 的内容

1/我正在尝试使用漂亮的汤提取脚本的一部分,但它没有打印任何内容。怎么了?URL="http://www.reuters.com/video/2014/08/30/woman-who-drank-restaurants-tainted-tea?videoId=341712453"oururl=urllib2.urlopen(URL).read()soup=BeautifulSoup(oururl)forscriptinsoup("script"):script.extract()list_of_scripts=soup.findAll("script")printlist_of_scr

python - BeautifulSoup .text 方法返回没有分隔符的文本(\n、\r 等)

我尝试从最大的俄罗斯歌词网站解析歌词http://amalgama-lab.com并将歌词(翻译和原创)从我的Vkontakte帐户保存到音频列表中(遗憾的是,amalgama没有任何API)importurllibfromBeautifulSoupimportBeautifulSoupimportvkontaktevk=vkontakte.API(token=)audios=vk.getAudios(count='2')#{u'artist':u'TheBeatles',u'url':u'http://cs4519.vkontakte.ru/u4665445/audio/4241af

python - 从 td 标签 BeautifulSoup Python 获取 href 属性链接

我是Python的新手,有人建议我使用BeautifulsoupforScrapping,我遇到了一个问题,即根据第4列中的年份从第2列的td标签中获取href属性。FilingsFormatDescriptionFilingDateFile/FilmNumber8-K DocumentsCurrentreport,items8.01and9.01Acc-no:00011931252013-05-03000-1003013813281424B2 DocumentsProspectus[Rule424(b)(2)]Acc-no:00011931252013-05-01

python - 无法安装 Beautifulsoup ("bs4 does not exist")

我正在努力在Windows上安装BeautifulSoup。到目前为止,我有:已将BeautifulSoup下载到“我的下载”。将其解压缩/提取到下载文件夹中。在命令提示符下,我运行了:C:"C:pathtobeautifulsoup\setup.py"install进程生成消息:runninginstallrunningbuildrunningbuild_py**error:packagedirectory'bs4'doesnotexist.**然而,在上面引用的BeautifulSoup路径中,确实有文件夹bs4。我错过了什么? 最佳答案

python - 使用 BeautifulSoup 获取属性值

我正在编写一个python脚本,它将在从网页解析后提取脚本位置。假设有两种情况:和someJS我能够从第二种情况中获取JS,即当JS写入标签内时。但是有什么办法,我可以从第一个场景中获取src的值(即提取脚本中src标签的所有值,例如http://example.com/something.js)这是我的代码#!/usr/bin/pythonimportrequestsfrombs4importBeautifulSoupr=requests.get("http://rediff.com/")data=r.textsoup=BeautifulSoup(data)forninsoup.fi

python - 使用 BeautifulSoup 从未关闭的特定元标记中提取内容

我正在尝试从特定的元标记中解析出内容。这是元标记的结构。前两个以反斜杠结束,但其余的没有任何结束标签。一旦我获得第三个元标记,之间的全部内容返回标签。我也试过soup.findAll(text=re.compile('keyword'))但这不会返回任何内容,因为关键字是元标记的属性。代码如下:importcsvimportreimportsysfrombs4importBeautifulSoupfromurllib.requestimportRequest,urlopenreq3=Request("https://angel.co/uber",headers={'User-Agent

python - 使用 beautifulsoup.find() 时出现奇怪的语法错误

这可能是显而易见的,但我被难住了(对python有点陌生,抱歉):page=urllib2.urlopen("http://www.somerandompage.com")soup=BeautifulSoup(page)currentDate=soup.find("span",class="posted-on")我正在页面中寻找以下元素:PostedonFriday,August12th,2011我收到的是语法错误:"test.py",line22currentDate=soup.find("span",class="posted-on")^SyntaxError:invalidsyn

python - 使用 BeautifulSoup 解析由 <br> 标记分隔的行?

我有一个看起来像这样的页面:CompanyA123MainSt.Suite101Someplace,NY1234CompanyB456MainSt.Someplace,NY1234有时有两个而不是三个“br”标签分隔条目。我将如何使用BeautifulSoup解析此文档并提取字段?我很困惑,因为我需要的文本位没有包含在我可以简单地遍历的段落(或类似)标签中。 最佳答案 您应该查看标签中的.strings属性,然后在其上使用“\n”.join()。 关于python-使用Beautiful