【发布时间】:2020-05-27 22:52:32
【问题描述】:
我对网络抓取非常陌生。我正在尝试从网页中提取 URL 列表,但 href 包含目录而不是 url。有没有办法获取 URL?
我的代码:
url='https://www.goodreads.com/shelf/show/bestsellers'
elements = requests.get(url).text
soup = BeautifulSoup(elements, "html.parser")
for link in soup.findAll('a',attrs={'class':"leftAlignedImage"}):
print (link['href'])
输出:
/book/show/5060378-the-girl-who-played-with-fire
/book/show/968.The_Da_Vinci_Code
/book/show/4667024-the-help
/book/show/2429135.The_Girl_with_the_Dragon_Tattoo
...
【问题讨论】:
标签: html python-3.x web-scraping beautifulsoup