【发布时间】:2018-07-19 17:46:02
【问题描述】:
第一行的所有元素都是指向后续页面的链接,我需要从中获取信息。主要问题是在 python 中打开这些链接。稍后我需要将该信息打印到 csv 文件中。 Here is image how it looks。 如何在 Python 中打开多个链接?谢谢
【问题讨论】:
-
看看scrapy。
标签: python html csv href export-to-csv
第一行的所有元素都是指向后续页面的链接,我需要从中获取信息。主要问题是在 python 中打开这些链接。稍后我需要将该信息打印到 csv 文件中。 Here is image how it looks。 如何在 Python 中打开多个链接?谢谢
【问题讨论】:
标签: python html csv href export-to-csv
requests 和 beautifulsoup 将轻松完成这项工作
import requests
from bs4 import BeautifulSoup
page = requests.get('http://firstpage.com/').text
soup = BeautifulSoup(page, 'html.parser')
links = soup.find_all('a')
for link in links:
print(link['href'])
http://docs.python-requests.org/en/master/ https://www.crummy.com/software/BeautifulSoup/bs4/doc/
【讨论】: