python lxm.html open local .html file,python 打开 本地html 文件方法

python 打开 本地html 文件方法

REF:

https://docs.python-guide.org/scenarios/scrape/

https://www.datacamp.com/community/tutorials/python-xml-elementtree

from lxml import html,etree
import requests

from bs4 import BeautifulSoup

"""
#-----------------------use URL-----------------------------------
base_url = "http://www.runoob.com/"
page = requests.get(base_url)
#page = requests.get('http://econpy.pythonanywhere.com/ex/001.html')
tree = html.fromstring(page.content)

#-----------------------use URL end-----------------------------------
"""


file ='./runoob_cainiao.html'
tree = html.parse(file)

#This will create a list of buyers:

lists = root.xpath('/html/body/div[4]/div/div[2]/div/a/strong/text()')

#print the lists
for list in lists:
    print('list: '+ '\n' ,list)

猜你喜欢

转载自blog.csdn.net/liugaoxingliushi/article/details/87973979
今日推荐