|  | 
 
| 
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  复制代码import requests
from lxml import etree
url = "https://sc.chinaz.com/ppt/free.html"
headers= {
    "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Mobile Safari/537.36"
}
response = requests.get(url,headers=headers)
response.encoding = "utf-8"
html_text = response.text
tree = etree.HTML(html_text)
#获取模板名称name和下载地址
div_list = tree.xpath('//div[@class="ppt-list  masonry"]/div')
for div in div_list:
    download_url ="https://sc.chinaz.com/ppt/"+ div.xpath('./div[2]/a/@href')[0]
    name= div.xpath('./div[2]/a/@title')[0]
    print(download_url, name)
 为什么打印出来没数据那?提示:Process finished with exit code 0
 
 
 
复制代码import requests
from lxml import etree
url = "https://sc.chinaz.com/ppt/free.html"
headers = {
    "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Mobile Safari/537.36"
}
response = requests.get(url, headers=headers)
response.encoding = "utf-8"
html_text = response.text
tree = etree.HTML(html_text)
# 获取模板名称name和下载地址
div_list = tree.xpath('//div[@class="ppt-list "]/div')
for div in div_list:
    download_url = "https://sc.chinaz.com/ppt/" + div.xpath('./div[2]/a/@href')[0]
    name = div.xpath('./div[2]/a/@title')[0]
    print(download_url, name)
 | 
 |