V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
fyl00
V2EX  ›  Python

求助:beautifulsoup中怎么查找变量

  •  
  •   fyl00 · 2013-09-08 11:07:27 +08:00 · 2776 次点击
    这是一个创建于 3898 天前的主题,其中的信息可能已经有所发展或是发生改变。
    用BS4做了个小爬虫,想爬取不同贴吧的签到数
    所以建立了一个list ,A
    然后通过for循环,对A中不同的贴吧进行抓取
    贴吧的主页链接定义成 home_link='http://tieba.baidu.com/f?kw='+a

    签到数要在这个页面(http://tieba.baidu.com/sign/index?kw=eminem#current_forum )中抓取
    所以写了下面一行代码
    soup.find('a',href="http://tieba.baidu.com/f?kw=eminem")

    怎么把这个href的值用home_link来表达呢

    因为楼主是新人,不知道有没有表达清楚
    1 条回复    1970-01-01 08:00:00 +08:00
    manoon
        1
    manoon  
       2013-09-08 12:18:09 +08:00
    直接soup.find('a',href=home_link)
    不行么?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2774 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 256ms · UTC 03:04 · PVG 11:04 · LAX 20:04 · JFK 23:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.