【发布时间】:2018-09-18 16:57:56
【问题描述】:
我能够成功地从网站上抓取一些文本,现在我正在尝试将文本加载到列表中,以便稍后将其转换为 Pandas DataFrame。
该网站以 scsv 格式提供数据,因此可以快速获取。
以下是我的代码:
import requests
from bs4 import BeautifulSoup
#Specify the url:url
url = "http://rotoguru1.com/cgi-bin/fyday.pl?week=1&year=2017&game=dk&scsv=1"
# Packages the request, send the request and catch the response: r
r = requests.get(url)
#Extract the response:html_doc
html_doc = r.text
soup = BeautifulSoup(html_doc,"html.parser")
#Find the tags associated with the data you need, in this case
# it's the "pre" tags
for data in soup.find_all("pre"):
print(data.text)
样本输出
周;年;GID;姓名;职位;团队;h/a;Oppt;DK积分;DK薪水 1;2017;1254;Smith, Alex;QB;kan;a;nwe;34.02;5400 1;2017;1344;Bradford, Sam;QB;min;h;nor;28.54;5900
【问题讨论】:
-
代码不适合我
-
对此深表歉意,我不确定出了什么问题。我正在运行 Python 3.6。我可以将确切的代码复制并粘贴到我的 IDE 中,然后它就会运行。
-
不用担心,您使用的是什么 IDE?
-
我正在使用 Spyder,它是最新 Anaconda 发行版附带的版本。
-
我也在使用 Spyder。代码运行但没有输出。
标签: python-3.x beautifulsoup python-requests