我使用的代码如下
import time
import mechanize
from bs4 import BeautifulSoup
import urllib2
import cookielib
cj = cookielib.CookieJar()
br = mechanize.Browser()
br.set_cookiejar(cj)
br.open("http://ipcamera.userlocal.jp/photos/latest?camera_id=123456")
br.select_form(nr=0)
br.form['login[camera_code]'] = '123456'
br.form['login[pass]'] = '7890'
br.submit()
soup = BeautifulSoup(br.response().read())
links = soup.find_all('img', src=True)
for link in links:
timestamp = time.asctime()
link = link["src"].split("src=")[-1]
print link
但是我得到了如下错误,我怎么能避免这些错误,或者是用密码刮网页的任何方式?非常感谢。
C:\Program Files (x86)\Python27\lib\site-packages\bs4\__init__.py:181: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.
The code that caused this warning is on line 21 of the file login.py. To get rid of this warning, change code that looks like this:
BeautifulSoup([your markup])
to this:
BeautifulSoup([your markup], "html.parser")
markup_type=markup_type))
答案 0 :(得分:1)
这不是错误 - 只是一个警告。由于您没有明确指定解析器。
修改此行 -
soup = BeautifulSoup(br.response().read(),"html.parser")
看看它是否有效。从移动设备回答所以代码没有格式化。一旦我在一小时内访问我的电脑就会这样做:)