Using BeautifulSoup to extract text without tags

Just loop through all the <strong> tags and use next_sibling to get what you want. Like this: for strong_tag in soup.find_all(‘strong’): print(strong_tag.text, strong_tag.next_sibling) Demo: from bs4 import BeautifulSoup html=””‘ <p> <strong class=”offender”>YOB:</strong> 1987<br /> <strong class=”offender”>RACE:</strong> WHITE<br /> <strong class=”offender”>GENDER:</strong> FEMALE<br /> <strong class=”offender”>HEIGHT:</strong> 5’05”<br /> <strong class=”offender”>WEIGHT:</strong> 118<br /> <strong class=”offender”>EYE COLOR:</strong> GREEN<br /> … Read more

Get meta tag content property with BeautifulSoup and Python

Provide the meta tag name as the first argument to find(). Then, use keyword arguments to check the specific attributes: title = soup.find(“meta”, property=”og:title”) url = soup.find(“meta”, property=”og:url”) print(title[“content”] if title else “No meta title given”) print(url[“content”] if url else “No meta url given”) The if/else checks here would be optional if you know that … Read more

Click a Button in Scrapy

Scrapy cannot interpret javascript. If you absolutely must interact with the javascript on the page, you want to be using Selenium. If using Scrapy, the solution to the problem depends on what the button is doing. If it’s just showing content that was previously hidden, you can scrape the data without a problem, it doesn’t … Read more