# 怎么发送请求
# pip install requests
import requests
# pip install lxml
from lxml import etree
# 发送给谁
url = 'https://www.tangsanxiaoshuo.com/dldl/3013.html'
#
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36'
}
# 发送请求
resp = requests.get(url,headers=headers)
#设置编码
resp.encoding = 'utf-8'
# 响应信息
#print(resp.text)
e = etree.HTML(resp.text)
info = e.xpath('//div[@class="nr_con"]')
title = e.xpath('//h1/span[@class]/a[@href="/dldl/3013.html"]')
print(info)
print(title)
# 保存
报错:
& "C:/../Python37/python.exe" "d:/phython/python/xiaoshuo.py"
File "", line 1
& "C:/../Python37/python.exe" "d:/phython/python /xiaoshuo.py"
^
SyntaxError: invalid syntax
报错的代码你总要放出来呀,你放的跟报错没有一毛钱关系