【发布时间】:2019-07-29 19:03:41
【问题描述】:
我需要提示如何从网站获取数据。我对网络抓取很陌生。特别是我无法访问该网站,因为它在另一个网络上本地运行。对于开发,我只有网站作为 html 文件。知道我的问题是我的以下代码出错。我认为问题很简单,但到目前为止我还没有一个想法。
import requests
import urllib.request
import time
from bs4 import BeautifulSoup
url = 'file:///tmp/mozilla/LiveData.html' # file is locally so far
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
我收到以下错误:
NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fc151db7550>: Failed to establish a new connection: [Errno -2] Name or service not known
当它是本地网站而不是“真实”网站时,它可能不起作用。感谢您的帮助!
【问题讨论】:
-
您不能在本地文件上使用
.get。而是使用open读取文件
标签: python web-scraping beautifulsoup get