Issue
I am trying to get one piece of data from a table online and the code I have so far is returning all the linked data preceded by the first <th in the first table. I only want to get back the Detected but not Quantified text.
import requests
from bs4 import BeautifulSoup as bs
import pandas as pd
c = "HMDB0059897"
res = requests.get("https://hmdb.ca/metabolites/" + c)
html_page = res.content
soup = bs(html_page, "html.parser")
table = soup.find("table")
headings = [th.get_text().strip() for th in table.find("tr").find_all("th")]
datasets = []
for row in table.find_all("tr")[1:]:
datasets = dict(zip(headings, (td.get_text() for td in row.find_all("td"))))
datasets.append(dataset)
print(datasets)
Solution
If I've understood you correctly, you want to only select the value of "Status" row:
import requests
from bs4 import BeautifulSoup as bs
c = "HMDB0059897"
res = requests.get("https://hmdb.ca/metabolites/" + c)
html_page = res.content
soup = bs(html_page, "html.parser")
status = soup.select_one('th:-soup-contains("Status") + td')
print(status.text)
Prints:
Detected but not Quantified
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.