解決lxml中沒有etree的問題
在使用爬蟲是:from lxml import etree時報錯,沒有etree這個庫,這是因為有的lxml包中沒有整合etree
解決方法:可以自己再選擇安裝帶etree的lxml,我的Python是3.6,下載的etree是4.2.1
下載地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/
下載後執行下圖程式碼不報錯說明安裝成功
etree使用程式碼例項(注:有時候匯入時飄紅並不程式碼出錯了)
import requests
import json
from lxml import etree
from selenium import webdriver
import requests
bro = webdriver.Firefox(executable_path = ‘D:\APPS\dir\geckodriver’)
d1 = open(‘etherscan_urls.json’,’r’).read()
d2 = json.loads(d1)
count = 0
for i in d2:
# d3 = requests.get(i)
bro.get(i)
selector = etree.HTML(bro.page_source)
data = selector.xpath(‘//*[@id=”ContentPlaceHolder1_divSummary”]/div[1]/table/tbody/tr[3]/td[2]/span/text()’)
data2 = selector.xpath(‘//*[@id=”ContentPlaceHolder1_divSummary”]/div[1]/table/tbody/tr[1]/td[2]/text()’)