赞
踩
import urllib.request
import requests
url = 'https://hz.lianjia.com/zufang/'
headers = (
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'
)
# headers = ('User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36')
request = urllib.request.Request(url,headers = headers) #构造request请求,加进去了头
response = urllib.request.urlopen(request) #发起请求 得到响应
html = response.read().decode('utf-8') #把响应读出来,用utf-8进行解码
出现问题:
File "C:\Users\DELL\AppData\Local\Temp;\ipykernel_5496\836135880.py", line 5 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36' ^ SyntaxError: invalid syntax
import urllib.request
import requests
url = 'https://hz.lianjia.com/zufang/'
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'
}
# headers = ('User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36')
request = urllib.request.Request(url,headers = headers) #构造request请求,加进去了头
response = urllib.request.urlopen(request) #发起请求 得到响应
html = response.read().decode('utf-8') #把响应读出来,用utf-8进行解码
是括号问题 就离谱
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。