我怎样才能得到一篇文章:作者,上传和更新的日期?

问题描述 投票:0回答:1

这是我删除文章的功能,现在我正在努力研究如何抓取作者的姓名,上传日期以及更新日期。我可以采取哪些方法来处理关于SF编年史的众多文章?

from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
# Initializing our title key
title_key = 'title'
dictionary.setdefault(title_key, [])

# Initializing our url key
url_key = 'url'
dictionary.setdefault(url_key, [])

# Initializing our author key
author_key = 'author'
dictionary.setdefault(text_key, [])

# Initializing our date key
author_key = 'date'
dictionary.setdefault(text_key, [])

# Initializing our date updated key
author_key = 'date_updated'
dictionary.setdefault(text_key, []) 

def article_scraper(url):
    # Opening up the connection, grabbing the page
    uClient = uReq(url)
    page_html = uClient.read()
    uClient.close()

    # HTML parsing
    page_soup = soup(page_html, "html.parser")

    dictionary['url'].append(url)
    dictionary['title'].append(page_soup.title.string)
    dictionary['author'] = page_soup.select("author.name")
    return(dictionary)

articles[0] = 'https://www.sfchronicle.com/news/bayarea/heatherknight/article/Special-education-teacher-a-prime-example-of-13560483.php'
article0 = article_scraper(articles[0])
python-3.x web-scraping beautifulsoup html-parsing
1个回答
0
投票

作者姓名:

author = soup.findAll("div", {"class": ""header-authors-name"})
© www.soinside.com 2019 - 2024. All rights reserved.