我想從本網站的表格和段落文本中提取各種元素。使用Python從網站中提取網頁元素
https://www.instituteforsupplymanagement.org/about/MediaRoom/newsreleasedetail.cfm?ItemNumber=30655
這是我使用的代碼:
import lxml
from lxml import html
from lxml import etree
import urllib2
source = urllib2.urlopen('https://www.instituteforsupplymanagement.org/about/MediaRoom/newsreleasedetail.cfm?ItemNumber=30656&SSO=1').read()
x = etree.HTML(source)
growth = x.xpath("//*[@id="home_feature_container"]/div/div[2]/div/table[2]/tbody/tr[3]/td[2]/p)")
growth
什麼是提取從一個網站,我想的元素,而無需每次都改變的XPath代碼的最佳方式是什麼?他們每個月都在同一個網站上發佈新數據,但XPath有時會發生一些變化。
什麼是你想要的元素一個例子嗎?您的XPath無效,無法在此頁面上進行測試。 –
我改變了xpath。我需要「製造一瞥」表中的元素。還有段落文字。 –