html - Inspecting elements and using XPATH to get the correct data python -


i'm trying scrape coinid's form website.

when inpecting element, id's seen here, when copying xpath get:

//*[@id="id-bitcoin"] 

i'm planning on using python code:

from lxml import html  import requests   page = requests.get('http://coinmarketcap.com/all/views/all/') tree = html.fromstring(page.content)  id = tree.xpath('')  print id 

but i'm not sure in element plug tree.xpath('')

i hoping

//span[@class="id"]/text() 

i tried printing tree understand data better, it's printing `what's syntax see data, tree.getdata() ?

any info on how can these coin id names appreciated, thanks.

i suppose trying id's of tr tags. id attribute of tag, can this:

from lxml import html import requests  page = requests.get('http://coinmarketcap.com/all/views/all/') tree = html.fromstring(page.content)  trs = tree.xpath('//table[@id="currencies-all"]/tbody/tr')  tr in trs:     print tr.attrib.get('id') 

you shall output this:

id-bitcoin id-ripple id-litecoin id-ethereum id-dash id-dogecoin ... 

if want data each row tr, can find each td tag inside tr , extract text content.

for tr in trs:     tds = tr.findall('td')     data = [td.text_content().strip() td in tds]     print data 

output:

['1', 'bitcoin', 'btc', '$ 6,815,160,833', '$ 452.70', '15,054,475', '$ 75,535,400', '-0.21 %', '5.19 %', '5.76 %'] ... 

you might need cleanup data.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -