代码拉取完成,页面将自动刷新
import requests
from lxml import etree
header = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"}
def lesson1():
url = 'https://www.imooc.com/course/list'
response = requests.get(url,headers=header)
print(response.status_code)
ehtml = etree.HTML(response.text)
print(ehtml.xpath("//p[@class='title ellipsis2']/text()"))
print(ehtml.xpath("//p[@class='one']/text()"))
print(ehtml.xpath("//p[@class='two clearfix']/span/text()"))
print(ehtml.xpath("//div[@class='img']//@style"))
def lesson2():
url = 'http://www.1ppt.com/moban/'
response = requests.get(url,headers=header)
response.encoding = response.apparent_encoding
print(response.status_code)
ehtml = etree.HTML(response.text)
print(ehtml.xpath("//li/h2/a/text()"))
text1 = ehtml.xpath("//li/span/text()[2]")
for i in text1:
print(i[1:])
print(ehtml.xpath("//li/a/img//@src"))
def lesson3():
url = 'https://jh.lianjia.com/ershoufang/'
response = requests.get(url,headers=header)
response.encoding = response.apparent_encoding
print(response.status_code)
ehtml = etree.HTML(response.text)
print(ehtml.xpath("//div[@class='title']/a/text()"))
print(ehtml.xpath("//div[@class='houseInfo']/text()"))
print(ehtml.xpath("//div[@class='title']/a/text()"))
print(ehtml.xpath("//div[@class='title']/a/text()"))
def lesson4():
url = 'https://hotel.qunar.com/'
response = requests.get(url,headers=header)
response.encoding = response.apparent_encoding
print(response.status_code)
ehtml = etree.HTML(response.text)
print(ehtml.xpath("//li[@class='item']/a/p[2]/text()"))
text1 = (ehtml.xpath("//div[@class='comm_box clearfix']/p/span/text()"))
text2 = (ehtml.xpath("//div[@class='comm_box clearfix']/p[@class='score']/text()"))
for i in range(len(text1)):
print(text1[i]+" "+text2[i])
print(ehtml.xpath("//div[@class='comm_box clearfix']/p[@class='comm_num']/text()"))
text3 = ehtml.xpath("//p[@class='price']/span[@class='y rmb']/text()")
text4 = ehtml.xpath("//p[@class='price']/text()")
text5 = ehtml.xpath("//p[@class='price']/span[@class='qi']/text()")
for i in range(len(text3)):
print(text3[i]+text4[i]+text5[i])
def lesson5():
url = 'https://china.nba.com/static/data/league/playerstats_All_All_All_0_All_false_2021_2_All_Team_points_All_perGame.json'
response = requests.get(url,headers=header)
response.encoding = response.apparent_encoding
print(response.status_code)
xhtml = response.json()
#print(res.text)
for i in range(50):
print(xhtml['payload']['players'][i]['playerProfile']['displayName'])
print(xhtml['payload']['players'][i]['teamProfile']['displayAbbr'])
print(xhtml['payload']['players'][i]['statAverage']['pointsPg'])
lesson5()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。