鱼C论坛

 找回密码
 立即注册
查看: 1665|回复: 3

[已解决]爬取网页源码与审查元素不一致如何解决?(cookies已加)

[复制链接]
发表于 2020-4-1 22:06:27 | 显示全部楼层    本楼为最佳答案   
这样
  1. import requests
  2. from lxml import etree
  3. url = 'https://music.163.com/discover/toplist'
  4. headers = {
  5.     'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
  6. }
  7. response = requests.get(url,headers = headers)
  8. text = response.text

  9. html = etree.HTML(text)
  10. songname = html.xpath('//ul[@class="f-hide"]//a/text()')
  11. address = html.xpath('//ul[@class="f-hide"]//a/@href')
  12. print(songname)
  13. print(address)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-21 03:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表