鍍金池/ 問(wèn)答/Python/ python 利用beautifulSoup提取頁(yè)面多個(gè)標(biāo)簽的文本內(nèi)容

python 利用beautifulSoup提取頁(yè)面多個(gè)標(biāo)簽的文本內(nèi)容

初學(xué)beautifulsoup解析庫(kù),拿一個(gè)招聘網(wǎng)頁(yè)練手,想達(dá)到提取多個(gè)標(biāo)簽的文本內(nèi)容,但是目前只可以提取到單個(gè)標(biāo)簽的單個(gè)文本內(nèi)容,多標(biāo)簽的文本如何提取?

from requests.exceptions import RequestException
import requests
from bs4 import BeautifulSoup


def get_one_page(url):
    try:
        response = requests.get(url)
        if response.status_code == 200:
            return response.text
        return None
    except RequestException:
        return None

def parse_one_page(html):
    soup = BeautifulSoup(html,'lxml')
    html = soup.find_all(class_='infolist-row')
    for a in html:
        print(a.find_all('a')[0])

def main():
    url = 'https://www.0951job.com/jobs/jobs-list.php'
    html = get_one_page(url)
    parse_one_page(html)

if __name__ == '__main__':
    main()

頁(yè)面url:https://www.0951job.com/jobs/...
class_='infolist-row'是提取內(nèi)容的主節(jié)點(diǎn),其余元素是副節(jié)點(diǎn)
所以請(qǐng)教大佬,如何提取副節(jié)點(diǎn)文本內(nèi)容并且遍歷以列表形式。是多次解析?
請(qǐng)大佬指點(diǎn)一下,謝謝

回答
編輯回答
青黛色

比如你要a.find_all('a')0鏈接url成列表的話

l = [a.find_all('a')[0]['href'] for a in html] #這樣l就是一個(gè)url的列表
2017年11月28日 01:26