马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
刚才再练习爬豆瓣,可是出现了ValueError: Invalid header name b'User:Agent'这个报错,上网查了下,说是在网页的headers里面有东西前面加了冒号,请问怎样把这个冒号删掉啊import bs4
import re
import requests
header = {'User:Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'}
res = requests.get('https://movie.douban.com/top250',headers = header)
soup = bs4.BeautifulSoup(res.text,'html.parser')
namelist = soup.find_all('div',class_='hd')
for each in namelist:
print(each.a.span.text)
是 User-Agent 不是 User:Agent
import bs4
import re
import requests
header = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'}
res = requests.get('https://movie.douban.com/top250',headers = header)
soup = bs4.BeautifulSoup(res.text,'html.parser')
namelist = soup.find_all('div',class_='hd')
for each in namelist:
print(each.a.span.text)
|