Skip to content

Instantly share code, notes, and snippets.

@davidcomfort
Created December 13, 2015 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidcomfort/5791b2ee37865e62050e to your computer and use it in GitHub Desktop.
Save davidcomfort/5791b2ee37865e62050e to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
session = requests.Session()
headers = {"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit 537.36 (KHTML, like Gecko) Chrome", "Accept":"text/html,application/xhtml+xml,application/xml; q=0.9,image/webp,*/*;q=0.8"}
url = "https://www.whatismybrowser.com/developers/what-http-headers-is-my-browser-sending"
req = session.get(url, headers=headers)
bsObj = BeautifulSoup(req.text)
print(bsObj.find("table",{"class":"table-striped"}).get_text)
<bound method Tag.get_text of <table class="table table-striped">
<tr>
<th>ACCEPT</th>
<td>text/html,application/xhtml+xml,application/xml; q=0.9,image/webp,*/*;q=0.8</td>
</tr>
<tr>
<th>ACCEPT_ENCODING</th>
<td>gzip, deflate</td>
</tr>
<tr>
<th>HOST</th>
<td>www.whatismybrowser.com</td>
</tr>
<tr>
<th>USER_AGENT</th>
<td>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit 537.36 (KHTML, like Gecko) Chrome</td>
</tr>
</table>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment