1 Star 0 Fork 0

周欣/爬虫zy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
阶段性测试2 2.90 KB
一键复制 编辑 原始数据 按行查看 历史
周欣 提交于 2021-12-15 03:03 . add 阶段性测试2.
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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhou-xin607/zx2.git
git@gitee.com:zhou-xin607/zx2.git
zhou-xin607
zx2
爬虫zy
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385