zoukankan      html  css  js  c++  java
  • 吴关于第三周BeautifulSoup个人作业中的易错点

    在BeautifulSoup类库中可用html_parser进行解析

    在html的文件中,要获得某标签的文本内容时,可用   对象名.select

    ('*')[0].text     其中[0]表示索引     *表示标签名

    例题:

    <h1  id=''tittle''>  Hello World    </h1>\

    <a  href=''#'' class=''link'' >   This is link1        </a>\

    <a   href=''# link2 ''  class=''link''>   This is link2   </a>\

    找出id为tittle属性所在的节点文本soup.select(''#tittle'')[0].text

    而找class为link的第一个节点的文本,则用soup.select(.link)[0].text

    在爬取数据时,在多层class关系中,用#表示id,用.表示class,用空格表示下一层关系

    pandas 类库中的DateFrame函数,可把列表转换成表格

    在BeautifulSoup中将内容格式化可用prettify()

    在继承关系(children/descendants/parent/parents)中,继承的返回结果为迭代器,需用enumerate来获取想要看到的内容

  • 相关阅读:
    position中的四种属性
    CSS中link和@import的区别
    隐藏对应元素的办法
    word20161217
    word20161216
    word20161215
    word20161214
    word20161213
    word201612012
    word20161211
  • 原文地址:https://www.cnblogs.com/ZHONGmy/p/9704202.html
Copyright © 2011-2022 走看看