import lxml,requests,sys
from bs4 import BeautifulSoup
from lxml import etree
reload(sys)
sys.setdefaultencoding("utf-8")
def main():
url = 'https://image.baidu.com/search/flip?tn=baiduimage&ie=utf-8&word=%E6%9A%B4%E8%B5%B0%E6%BC%AB%E7%94%BB&pn=0'
req = requests.get(url).content
# soup = BeautifulSoup(req.content,'lxml')
# imgs = soup.find_all('img')
content = etree.HTML(req)
paths = content.xpath('//*[@id="imgid"]/ul/li[1]/a/img/text()')
# for img in imgs:
#
# print img
# for img in imgs :
print paths
main()
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
闭关修行中......