【发布时间】:2020-07-19 03:11:28
【问题描述】:
我正在尝试使用 Python 的 request 和 bs4 抓取一个网站来编译和总结新闻。我尝试访问的链接(href)出现在 Chrome 的开发者工具中,路径如下:
"/html/body/div/div/div/main/article/div/div/section/div/section/div/div[3]/ul/li[1]/a"
我尝试了所有方法来提取它们,但我意识到 Python 的 html 输出并没有下降到那个水平。它停留在:
"/html/body/div/div/div/main/article/div/div/section/div/section"
我正在使用以下代码:
import requests
from bs4 import BeautifulSoup
url = 'https://www.gp.com/news'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
for url in soup.find_all('a'):
print(url.get('href'))
非常感谢您能给我的任何帮助,因为我完全没有想法。另外,我对编程完全陌生,因此希望您的答案尽可能地简单化。
提前非常感谢!
【问题讨论】:
标签: python beautifulsoup python-requests href screen-scraping