【发布时间】:2021-11-30 18:34:19
【问题描述】:
我正在尝试使用网络爬虫从体育、主页、世界、商业和技术中获取新闻内容, 我有这段代码,它在其中获取页面的标题和 url,我如何获取页面的 url 并打开它并在正文中获取它的内容
#python code
import requests
from bs4 import BeautifulSoup
url = "https://www.aaa.com"
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
print(soup.prettify())
headlines = soup.find('body').find_all('h3')
for title in soup.findAll('a', href=True): #give me type
if re.search(r"\d+$", title['href']):
print(title['href'])
【问题讨论】:
标签: python web-crawler