『壹』 python BeautifulSoup不能解析<script>...<script>之间的内容
什么意思?你是想把javascript产生的内容自动解析出来还是只提取出字符串中的内容.
『贰』 python3 用BeautifulSoup 爬取指定ul下的a标签
用select('ul的css路径').find_all(...)
css路径直接用浏览器开发视图,从ul复制就好,当然也可以把前面多余的部分删掉

『叁』 怎么使用beautifulsoup获取指定div标签内容
f = urllib2.urlopen(url)
req = f.read()
soup = BeautifulSoup(req)
content = soup.findAll(attrs={"name":"readonlycounter2"})
subId = content[0].string.split(',')[1]
subName = soup.html.body.h1.span.string
content = soup.findAll(attrs={"class":"subdes_td"})
subType = content[0].string
subLeg = content[1].string
content = soup.findAll(attrs={"colspan":"3"})
subTime = content[2].string
subFile = content[7].div.string
『肆』 怎么用python的BeautifulSoup来获取html中div的内容
# -*- coding:utf-8 -*-
#标签操作
from bs4 import BeautifulSoup
import urllib.request
import re
#如果是网址,可以用这个办法来读取网页
#html_doc = ""
#req = urllib.request.Request(html_doc)
#webpage = urllib.request.urlopen(req)
#html = webpage.read()
html="""
"""
soup = BeautifulSoup(html, 'html.parser') #文档对象
# 类名为xxx而且文本内容为hahaha的div
for k in soup.find_all('div',class_='atcTit_more'):#,string='更多'
print(k)
『伍』 python 使用BeautifulSoup库提取div标签中的文本内容
因为你的html不是合法的xml格式,标签没有成对出现,只能用html解析器
frombs4importBeautifulSoup
s="""
</span><br><spanstyle='font-size:12.0pt;color:#CC3399'>714659079qqcom2014/09/1010:14</span></p></div>
"""
soup=BeautifulSoup(s,"html.parser")
printsoup
printsoup.get_text()
如果你想用正则的话,只要把标签匹配掉就可以了
importre
s="""
</span><br><spanstyle='font-size:12.0pt;color:#CC3399'>714659079qqcom2014/09/1010:14</span></p></div>
"""
dr=re.compile(r'<[^>]+>',re.S)
dd=dr.sub('',s)
printdd
如果解决了您的问题请采纳!
如果未解决请继续追问
『陆』 Python beautifulsoup 获取标签中的值 怎么获取
age = soup.find(attrs={"class":"age"}) #你这里find只要一个attrs参数不会报错。
if age == None: #简单点可以用 if not age:
print u'没有找到'
else:
soup.find(attrs={"class":"name"})
#否则用findAll找出所有具有这个class的tr
tr = html.find("tr", attrs={"class":"show_name"})
tds = tr.findAll("td")
for td in tds:
print td.string # 或许不是string属性,你可以用dir(td)看看有哪些可用的。

(6)beautifulsoup获取js扩展阅读:
1、如果是函数定义中参数前的*表示的是将调用时的多个参数放入元组中,**则表示将调用函数时的关键字参数放入一个字典中。
1)如定义以下函数:
def func(*args):print(args)
当用func(1,2,3)调用函数时,参数args就是元组(1,2,3)
2)如定义以下函数:
def func(**args):print(args)
当用func(a=1,b=2)调用函数时,参数args将会是字典{'a':1,'b':2}
学python的同时一定会接触到其他技术,毕竟光会python这门语言是不够的,要看用它来做什么。比如说用 python做爬虫,就必须接触到html, http等知识。
python是现在最火的数据分析工具语言python的进阶的路线是数据清洗,爬虫,数据容器,之后是卷积,线性分析,和机器学习,区块连,金融方面的量化等高端进阶。
『柒』 如何用 beautifulsoup抓取js数据
代码函数如下:
foundTds = soup.findAll(name="td", attrs={"style":"text-align:right;"}, text=re.compile("\d+(,\d+)*\.\d+"));
# !!! here match only the match re.compile text, not whole td tag
print "foundTds=",foundTds; #foundTds= [u'', u'1,']
if(foundTds):
for eachMoney in foundTds:
print "eachMoney=",eachMoney;
# eachMoney= 2
# eachMoney= 1
if __name__ == "__main__":
beautifulsoup_capture_money();
『捌』 python 用 beautifulsoup 获得 <div id="z"></div>的东西
一、你取到的跟浏览器不一样,这一般是因为内容是js生成或者js以ajax取到然后更新进去的。
想要自己写代码解决恐怕你要自己分析一下网页所带的js的功能了,或者想偷懒的话用webbrowser之类的模块通过浏览器来取得内容。
二、要取div的id属性用BeautifulSoup即可达到目的,要是装了PyQuery的就更简单,下面给个BeautifulSoup的例子:
from bs4 import BeautifulSoup
sp = BeautifulSoup('<div id="z"></div>')
assert(sp.div['id'],'z')
print sp.div['id']
『玖』 phython中用beautiful soup如何获得html某个属性的值
1、首先打开编辑器。
