Python Forum
How to find particular text from td tag using bs4
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to find particular text from td tag using bs4
#1
hi,

I have some html links and i want to find some particular text and it's next text also. I am using regex but receiving lost of empty lists.

These are links:

https://www.99acres.com/mailers/mmm_html...7-558.html https://www.99acres.com/mailers/mmm_html...-2016.html https://www.99acres.com/mailers/mmm_html...7-553.html

text i am finding Area Range: Next Text also Possession: next text also for example possession 2019 Price: next text also

below are my codes:

import requests
from bs4 import BeautifulSoup
import csv
import json
import itertools
import re
file = {}
final_data = []
final = []
textdata = []
def readfile(alldata, filename):
    with open("./"+filename, "w") as csvfile:
        csvfile = csv.writer(csvfile, delimiter=",")
        for i in range(0, len(alldata)):
            csvfile.writerow(alldata[i])
def parsedata(url, values):
    r = requests.get(url, values)
    data = r.text
    return data

def getresults():
    global final_data, file
    with open("Mailers.csv", "r") as f:
        reader = csv.reader(f)
        next(reader)
        for row in reader:
            ids = row[0]
            link = row[1]
            html = parsedata(link, {})
            soup = BeautifulSoup(html, "html.parser")
            titles = soup.title.text
            td = soup.find_all("td")
            for i in td:
                sublist = []
                data = i.text
                pattern = r'(Possession:)(.)(.+)'
                x1 = re.findall(pattern, data)
                sublist.append(x1)
                sublist.append(link)
                final_data.append(sublist)
    print(final_data)
    return final_data
def main():
    getresults()
    readfile(final_data, "Data.csv")
main()
Reply


Messages In This Thread
How to find particular text from td tag using bs4 - by Prince_Bhatia - Sep-24-2018, 06:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why doesn't my spider find body text? sigalizer 5 4,298 Oct-30-2019, 11:35 PM
Last Post: sigalizer
  XML Parsing - Find a specific text (ElementTree) TeraX 3 4,025 Oct-09-2018, 09:06 AM
Last Post: TeraX
  BS4 Not Able To Find Text In CSS Comments digitalmatic7 4 5,178 Feb-27-2018, 03:45 AM
Last Post: digitalmatic7

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020