简体   繁体   中英

Scraping websites with BS4

I have this code

import requests
from bs4 import BeautifulSoup


result = requests.get("http://www.cvbankas.lt/")
src = result.content
soup = BeautifulSoup(src, 'lxml')

urls = []
for article_tag in soup.find_all("article"):
        a_tag = article_tag.find('a')
        urls.append(a_tag.attrs['href'])
        div_tag = article_tag.find('span')
        urls.append(div_tag.attrs['class'])

print(urls)

Can anyone explane me how to get the data marked in red?

网页源截图

You can get span with the class label "salary_amount"

salary_object = article_tag.find("span", class_= "salary_amount")

and then extract the text with the.text attribute of the created object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM