【发布时间】:2018-10-07 11:21:27
【问题描述】:
我想爬取当前托管在本地的网站。不能爬取本地托管的网站吗?我收到此错误:
File "C:/Users/hero/PycharmProjects/project/Crawler.py", line 22, in <module>
imagefile.write(urllib.request.urlopen("http://192.168.1.1/Webpage.html"+img_src).read())
urllib.error.HTTPError: HTTP Error 404: Not Found
爬虫代码:
import urllib.request
from bs4 import BeautifulSoup
def make_soup(url):
thepage = urllib.request.urlopen(url)
soupdata = BeautifulSoup(thepage, "html.parser")
return soupdata
i = 1
soup = make_soup("http://192.168.1.1/Webpage.html")
unique_srcs = []
for img in soup.findAll('img'):
if img.get('src') not in unique_srcs:
unique_srcs.append(img.get('src'))
for img_src in unique_srcs:
filename = str(i)
i = i + 1
imagefile = open(filename + '.png', 'wb')
imagefile.write(urllib.request.urlopen("http://192.168.1.1/Webpage.html"+img_src).read())
imagefile.close()
【问题讨论】:
-
你好。这听起来像是一个愚蠢的问题,但您是否尝试过使用浏览器访问192.168.1.1/Webpage.html?你的网络呢? 192.168.1.1 通常是路由器的 IP 地址,如果它是您的 Web 服务器的 IP,我会感到惊讶。
-
192.168.1.1 这是我为发布问题而保留的 ip。但是,当我保留自己的 ip 时,它正在工作。但是,爬取有错误
标签: python beautifulsoup web-crawler