我能够成功地从一个网站中提取数据,除了一个字段,它的标签是img。以下是代码:
#import pandas as pd
import re
from urllib2 import urlopen
from bs4 import BeautifulSoup
# gets a file-like object using urllib2.urlopen
url = 'http://ecal.forexpros.com/e_cal.php?duration=daily'
html = urlopen(url)
soup = BeautifulSoup(html)
# loop
使用BeautifulSoup,我在Python中有一点点屏幕刮擦代码,这让我头疼。对html的小改动使我的代码中断,但我不明白为什么它不能工作。这基本上是一个html解析时的演示:
soup=BeautifulSoup("""
<td>
<a href="https://alink.com">
Foo Some text Bar
</a>
</td>
""")
links = soup.find_all('a',text=re.com
我正在试着从一个网站上提取一些信息。我需要点击'a‘标签中的一个链接。我能够到达标签。但是当我尝试点击它的时候。我收到一个名为'NoneType‘对象不可调用的错误。
from selenium import webdriver
import time
from bs4 import BeautifulSoup
import pandas as pd
browser = webdriver.Chrome()
browser.get("url")
browser.find_element_by_class_name('formButton').c
html如下所示:
<td class='Thistd'><a ><img /></a>Here is some text.</td>
我只想在<td>中得到字符串。我不需要<a>...</a>。我怎么能这么做?
我的代码:
from bs4 import BeautifulSoup
html = """<td class='Thistd'><a><img /></a>Here is some t
我想从td标签中提取包含br标签的文本。
from bs4 import BeautifulSoup
html = "<td class=\"text\">This is <br/>a breakline<br/><br/></td>"
soup = BeautifulSoup(html, 'html.parser')
print(soup.td.string)
实际产出:None
预期产出:This is a breakline
我正在分析一个有1000多个href链接的大型html网站。我正在使用Beautifulsoup来获取所有的链接,但当我再次运行程序时,beautifulsoup无法处理它。(查找特定的所有'td‘标签。我将如何克服这个问题?虽然我可以用urllib加载html页面,但是不能打印所有的链接。当我将它与find one 'td‘标签一起使用时,它被传递了。
Tag = self.__Page.find('table', {'class':'RSLTS'}).findAll('td')
print Ta
我正在用BeautifulSoup做一些超文本标记语言清理。对Python和BeautifulSoup都是新手。根据我在Stackoverflow上找到的答案,我已经正确地删除了标签,如下所示:
[s.extract() for s in soup('script')]
但是如何删除内联样式呢?例如:
<p class="author" id="author_id" name="author_name" style="color:red;">Text</p>
<img class=
我是python/BeautifulSoup的初学者,我正在尝试提取<td width="473" valign="top"> -> <strong>中的所有内容。
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
<title>MIEJSKI OŚRODEK KULTURY W ŻORACH Repertuar Kina Na Starówc
我正在尝试使用Python和BeautifulSoup访问某些td标签中的内容。我可以获得满足条件的第一个td标记(使用find),也可以获取所有的td标记(使用findAll)。
现在,我可以只使用findAll,获取所有内容,并从中获取我想要的内容,但这似乎效率很低(即使我对搜索进行了限制)。有没有办法转到满足我想要的条件的某个td标签?比如说第三个,还是第十个?
到目前为止,我的代码如下:
from __future__ import division
from __future__ import unicode_literals
from __future__ import print
django对象中文本中的delete表有问题。有时,我的<p>标记在<table>中。如何避免删除p标记而删除表标记。现在,我正在删除表,当p标记在表之外时,它是可以的。为了完成所有这些事情,我正在使用BeautifulSoup。
for obj in article:
soup_en = BeautifulSoup(obj.text_en, features="html5lib")
if soup_en.find_all('table'):
for i in soup_en.select('ta
使用BeautifulSoup,我有:
from bs4 import BeautifulSoup
url= "http://scores.espn.go.com/ncb/playbyplay?gameId=400551234"
import urllib2
page= urllib2.urlopen(url).read()
soup= BeautifulSoup(page)
tr_tags= soup.findAll("tr", attrs={"class": True})
for tag in tr_tags:
if "ev