马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import requests
from lxml import etree
import re
url = 'http://www.1ppt.com/moban/shengri/'
UA = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36'}
r1 = requests.get(url=url,headers=UA).text
x1 = etree.HTML(r1)
fulr = x1.xpath('//ul[@class = "tplist"]//@href')
fulr = ['http://www.1ppt.com'+fulr for fulr in fulr]
fname = x1.xpath('//ul[@class = "tplist"]//@alt')
print(fname)
设置下编码即可:r1.encoding = 'gbk',完整代码:
import requests
from lxml import etree
import re
url = 'http://www.1ppt.com/moban/shengri/'
UA = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36'}
r1 = requests.get(url=url,headers=UA)
r1.encoding = 'gbk'
x1 = etree.HTML(r1.text)
fulr = x1.xpath('//ul[@class = "tplist"]//@href')
fulr = ['http://www.1ppt.com'+fulr for fulr in fulr]
fname = x1.xpath('//ul[@class = "tplist"]//@alt')
print(fname)
|