我试图从以下链接:中删除数据,但是在执行以下代码时:
import urllib
from bs4 import BeautifulSoup
import xml.etree.ElementTree as ET
url= "https://www.kickstarter.com/projects/298226251/subform-a-modern-tool-for-digital-product-designer"
html=urllib.urlopen(url).read()
soup=BeautifulSoup(html,"html.parser")
我试图访问一个类HTML中唯一的文本。我试图应用于 BeautifulSoup,但总是收到相同的错误消息或该标记中的所有项。
My code.py
from urllib.request import urlopen
from bs4 import BeautifulSoup
import requests
import re
url = "https://www.auchandirect.pl/auchan-warszawa/pl/pepsi-cola-max-niskokaloryczny-napoj-gazowany-o-smaku-cola/p-98502176"
r
我在使用Beautifulsoup解析带有"class“属性的HTML元素时遇到了问题。代码如下所示
soup = BeautifulSoup(sdata)
mydivs = soup.findAll('div')
for div in mydivs:
if (div["class"] == "stylelistrow"):
print div
在脚本结束后,我在同一行得到了一个错误。
File "./beautifulcoding.py", line 130, in getlanguage
我写了下面这行:
[x['href'] for x in BeautifulSoup(data, parseOnlyThese=SoupStrainer('a'))]
数据是由python2.7中的urllib.urlopen(XXX).read()实现的。
当XXX是一个完全由英文字符组成的页面时,它工作得很好,比如。但是当它在一个页面上有一些中文字符时,它就失败了。将会有一个KeyError。[x for ...]返回一个空列表。
更重要的是,如果没有parseOnlyThese=SoupStrainer('a'),两个都可以。
SoupSt
代码: from bs4 import BeautifulSoup
# Opening the html file
HTMLFile = open("index.html", "r")
# Reading the file
contents = HTMLFile.read()
# Creating a BeautifulSoup object and specifying the parser
S = BeautifulSoup(contents, 'html.parser')
print (S.find_all("
对于如何使用BeautifulSoup导航HTML,我有点困惑。
import requests
from bs4 import BeautifulSoup
url = 'http://examplewebsite.com'
source = requests.get(url)
content = source.content
soup = BeautifulSoup(source.content, "html.parser")
# Now I navigate the soup
for a in soup.findAll('a'):
此代码提取课堂上所有学生的标记,并使用results.txt将结果存储在文件BeautifulSoup中。我正在寻找代码评审和建议。
from bs4 import BeautifulSoup
import requests
file = open("results.txt","w")
for roll in range(1,60):
if roll in range(1,10):
rollstr = '0'+str(roll)
else:
rollstr = str(roll)
从网页上,我想得到所有的链接和标题字符串。我使用BeautifulSoup 4进行刮擦。网页上的链接如下所示:
<a href='http://www.example1.com' title='A small secret for better estimates #4/16/2014 8:10:30 AM'> Example 1 </a>
<a href='http://www.example2.com' title='Don't make me think #4/9/2014 4:36:07 AM
import requests
r=requests.get('https://www.crummy.com/software/BeautifulSoup/')
from bs4 import BeautifulSoup as bs
soup=bs(r.text,'html.parser')
links=[x['href'] for x in soup.find_all('a')]
links 错误是: KeyError
Traceback (most rec