logo
Loading...

soup.find(name='div', attrs={'id':'mw-content-text'}).find_all(name='p') 裡面的表示法 - Cupoy

content = html_soup.find(name='div', attrs={'id':'...

pycrawler,pycrawler-d16

soup.find(name='div', attrs={'id':'mw-content-text'}).find_all(name='p') 裡面的表示法

2020/07/13 下午 04:00
Python網路爬蟲討論版
ethanqq
觀看數:4
回答數:1
收藏數:0
pycrawler
pycrawler-d16

content = html_soup.find(name='div', attrs={'id':'mw-content-text'}).find_all(name='p')


請問如果上面的name=  作用是?

 

content2 = html_soup.find(id='mw-content-text').find_all('p')


下面跟上面有什麼不同呢?(優缺點)


感謝喔!

回答列表

  • 2020/07/14 下午 11:34
    張維元 (WeiYuan)
    贊同數:1
    不贊同數:0
    留言數:2

    1. 請問如果上面的name=  作用是?


    => 標籤是 div 的物件


    2. 下面跟上面有什麼不同呢?


    => 下面沒有指定標籤,如果改成這樣就相同:


    ```

    html_soup.find('div', id='mw-content-text').find_all('p')

    ```


    原則上沒差,只是寫法差異而已,沒有什麼特別的優缺點。