【发布时间】:2018-12-30 19:43:00
【问题描述】:
我想从网络获取所有 URL,并将结果存储为变量。到目前为止,我找到了以下代码:
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("https://www.sport.es/") # Insert your URL to extract
bsObj = BeautifulSoup(html.read());
for link in bsObj.find_all('a'):
print(link.get('href'))
结果正是我想要的,但我需要将其存储为变量来构建数据框。我该怎么做?
谢谢大家。
最好的问候,
【问题讨论】:
-
为什么需要将 url 存储在 pandas 数据框中?
-
因为我需要使用存储在列中的不同变量(不仅是 url)...
标签: python python-3.x pandas dataframe web-scraping