How to get inner text value of an HTML tag with BeautifulSoup bs4?

Use .text to get the text from the tag. oname = soup.find(“title”) oname.text Or just soup.title.text In [4]: from bs4 import BeautifulSoup In [5]: import requests In [6]: r = requests.get(“http://stackoverflow.com/questions/27934387/how-to-retrieve-information-inside-a-tag-with-python/27934403#27934387”) In [7]: BeautifulSoup(r.content).title.text Out[7]: u’html – How to Retrieve information inside a tag with python – Stack Overflow’ To open a file and use … Read more

BeautifulSoup returns None even though the element exists

try this code: from selenium import webdriver import time from bs4 import BeautifulSoup driver = webdriver.Chrome() url= “http://www.pro-football-reference.com/boxscores/201309050den.htm” driver.maximize_window() driver.get(url) time.sleep(5) content = driver.page_source.encode(‘utf-8’).strip() soup = BeautifulSoup(content,”html.parser”) officials = soup.findAll(“table”,{“id”:”officials”}) for entry in officials: print(str(entry)) driver.quit() It will print: <table class=”suppress_all sortable stats_table now_sortable” data-cols-to-freeze=”0″ id=”officials”><thead><tr class=”thead onecell”><td class=” center” colspan=”2″ data-stat=”onecell”>Officials</td></tr></thead><caption>Officials Table</caption><tbody> <tr data-row=”0″><th … Read more

Install Beautiful Soup using pip [duplicate]

pip is a command line tool, not Python syntax. In other words, run the command in your console, not in the Python interpreter: pip install beautifulsoup4 You may have to use the full path: C:\Python27\Scripts\pip install beautifulsoup4 or even C:\Python27\Scripts\pip.exe install beautifulsoup4 Windows will then execute the pip program and that will use Python to … Read more