【问题标题】:How to get links to all articles on a website? [duplicate]如何获取网站上所有文章的链接? [复制]
【发布时间】:2020-05-07 00:28:10
【问题描述】:

您好,我对 BS4 或 selenium 真的很陌生。我想知道是否有办法获取网站上所有文章的链接。

例如https://uk.yahoo.com 会有很多新闻文章。我怎样才能(或有可能)获得所有这些文章的链接列表?

【问题讨论】:

标签: python selenium web-scraping beautifulsoup


【解决方案1】:

试试这个。添加您自己的用户代理字符串。

import re
import requests
from bs4 import BeautifulSoup

response = requests.get(url='https://uk.yahoo.com ', headers={'User-Agent':''})
soup = BeatifulSoup(response.content, 'html.parse')

links = []
for link in soup.findAll('a', attrs={'href': re.compile('^https://')}
    links.append(link.get('href'))
print(links)

【讨论】:

    猜你喜欢
    • 2016-03-05
    • 2021-11-26
    • 1970-01-01
    • 2014-08-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 2021-08-19
    • 1970-01-01
    相关资源
    最近更新 更多