write me code for get data form html
- User
write me code for get data form html
Assistant
Here is some Python code to get data from HTML:
pythonimport requests from bs4 import BeautifulSoup url = "http://example.com" response = requests.get(url) html = response.text soup = BeautifulSoup(html, "html.parser") # Get page title page_title = soup.title.text # Get all paragraph texts para_texts = [] paras = soup.find_all("p") for p in paras: para_texts.append(p.text) # Get text from div with id="main" main_div = soup.find("div", id="main") main_text = main_div.text # Get href attributes from all anchor tags links = [] anchors = soup.find_all("a") for a in anchors: links.append(a.get("href")) print(page_title) print(para_texts) print(main_text) print(links)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.