python3用BeautifulSoup抓取a标签

# -*- coding:utf-8 -*-
#python 2.7
#XiaoDeng
#http://tieba.baidu.com/p/2460150866

from bs4 import BeautifulSoup
import urllib.request

html_doc = "http://tieba.baidu.com/p/2460150866"
req = urllib.request.Request(html_doc)
webpage = urllib.request.urlopen(req)
html = webpage.read()

soup = BeautifulSoup(html, ‘html.parser‘)

#抓取class=‘app_icon_link‘的a标签
img_src=soup.findAll("a",{‘class‘:‘app_icon_link‘})   #抓取a标签
for img in img_src:
    img=img.findAll(‘img‘)
    for k in img:
        k=k.get(‘src‘)
        print(k)
时间: 2024-08-06 13:22:58

python3用BeautifulSoup抓取a标签的相关文章

python3用BeautifulSoup抓取div标签

# -*- coding:utf-8 -*- #python 2.7 #XiaoDeng #http://tieba.baidu.com/p/2460150866 #标签操作 from bs4 import BeautifulSoup import urllib.request import re #如果是网址,可以用这个办法来读取网页 #html_doc = "http://tieba.baidu.com/p/2460150866" #req = urllib.request.Req

python3用BeautifulSoup抓取id='xiaodeng',且正则包含‘elsie’的标签

# -*- coding:utf-8 -*- #python 2.7 #XiaoDeng #http://tieba.baidu.com/p/2460150866 #使用多个指定名字的参数可以同时过滤tag的多个属性 from bs4 import BeautifulSoup import urllib.request import re #如果是网址,可以用这个办法来读取网页 #html_doc = "http://tieba.baidu.com/p/2460150866" #req

python3用BeautifulSoup抓取图片地址

# -*- coding:utf-8 -*- #python 2.7 #XiaoDeng #http://tieba.baidu.com/p/2460150866 #抓取图片地址 from bs4 import BeautifulSoup import urllib.request html_doc = "http://tieba.baidu.com/p/2460150866" req = urllib.request.Request(html_doc) webpage = urlli

BeautifulSoup抓取门户网站上的链接

使用BeautifulSoup抓取门户网站上的所有跳转链接 from bs4 import BeautifulSoup import urllib2 request = urllib2.Request('http://www.163.com') response = urllib2.urlopen(request) html_doc = response.read() soup = BeautifulSoup(html_doc , from_encoding = "gb18030")

python爬虫:使用urllib.request和BeautifulSoup抓取新浪新闻标题、链接和主要内容

案例一 抓取对象: 新浪国内新闻(http://news.sina.com.cn/china/),该列表中的标题名称.时间.链接. 完整代码: from bs4 import BeautifulSoup import requests url = 'http://news.sina.com.cn/china/' web_data = requests.get(url) web_data.encoding = 'utf-8' soup = BeautifulSoup(web_data.text,'

使用BeautifulSoup抓取

年前有个坑爹的需求来了,要把某点评网商户数据都给获取下来存储于数据库,好啦其实这个东西是蛮简单的: 首先到点评网把城市数据给拷贝下来,当然你也可以写个脚本把数据抓取下来,不够我没这么干:好了下面是用于抓取数据的脚本,下面我分享下给大家: 城市列表: alashan|57|阿拉善 anshan|58|鞍山 anqing|117|安庆 anhuisuzhou|121|宿州 anyang|164|安阳 aba|255|阿坝 anshun|261|安顺 ali|288|阿里 ankang|297|安康

Python3简单爬虫抓取网页图片

现在网上有很多python2写的爬虫抓取网页图片的实例,但不适用新手(新手都使用python3环境,不兼容python2),所以我用Python3的语法写了一个简单抓取网页图片的实例,希望能够帮助到大家,并希望大家批评指正. 1 import urllib.request 2 import re 3 import os 4 import urllib 5 #根据给定的网址来获取网页详细信息,得到的html就是网页的源代码 6 def getHtml(url): 7 page = urllib.r

利用BeautifulSoup抓取新浪网页新闻的内容

第一次写的小爬虫,python确实功能很强大,二十来行的代码抓取内容并存储为一个txt文本 直接上代码 #coding = 'utf-8' import requests from bs4 import BeautifulSoup import sys reload(sys) sys.setdefaultencoding("utf-8") #抓取web页面 url = "http://news.sina.com.cn/china/" res = requests.g

Python结合BeautifulSoup抓取知乎数据

本文主要介绍利用Python登录知乎账号,抓取其中的用户名.用户头像.知乎的问题.问题来源.被赞数目.以及回答者.其中数据是配合Beautiful Soup进行解析的. 首先,要解决的是知乎登录问题.在程序中登录知乎我们直接提供用户名和密码是无法进行登录的,这里我们采用一个比较笨拙的办法直接在发送请求过程中附带上cookies.这个cookies值我们可以通过在火狐浏览器登录知乎时用firebug直接捕获.cookies获取如下图所示: [info] email =youremail passw