|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import requests
- import lxml.html
- myheaders = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"}
-
- http_response = requests.get('https://movie.douban.com', headers=myheaders)
- http_response.encoding = 'utf-8'
-
- html = lxml.html.fromstring(http_response.text)
- title = html.xpath('//*[@id="billboard"]/div[2]/table/tr[1]/td[2]/a')
- print(title)
- print(title[0].text_content())
复制代码
print(title)返回一个数组,能解释一下print(title[0].text_content())的原理吗?
其他语言学多了哈哈,Python 里面没有数组概念 不算 numpy 那些,返回的是个列表
title[0].text_content() 就是 title 的第一个内容里的 文本提取出来
|
|