简体   繁体   中英

How To Scrape Specific Chracter in Selenium using Python

I Want To Scrape 70 character in this HTML code:

<p>2) Proof of payment emailed to satrader03<strong>@gmail.com</strong> direct from online banking 3) Selfie of you holding your ID 4) Selfie of you holding your bank card from which payment will be made OR 5) Skype or what's app Video call while logged onto online banking displaying account name which should match personal verified name Strictly no 3rd party payments</p>

I Want To Know How To Scrape Specific Character with selenium for example i want to scrape 30 character or other

Here is my code:

description = driver.find_elements_by_css_selector("p")
items = len(title)
with open('btc_gmail.csv','a',encoding="utf-8") as s:
    for i in range(items):
        s.write(str(title[i].text) + ',' + link[i].text + ',' + description[i].text + '\n')

How to scrape 30 characters or 70 or something


Edit (full code):

driver = webdriver.Firefox()

r = randrange(3,7)


for url_p in url_pattren:   
    time.sleep(3)   
    url1 = 'https://www.bing.com/search?q=site%3alocalbitcoins.com+%27%40gmail.com%27&qs=n&sp=-1&pq=site%3alocalbitcoins+%27%40gmail.com%27&sc=1-31&sk=&cvid=9547A785CF084BAE94D3F00168283D1D&first=' + str(url_p) + '&FORM=PERE3'
    driver.get(url1)
    time.sleep(r)
    title = driver.find_elements_by_tag_name('h2')
    link = driver.find_elements_by_css_selector("cite")
    description = driver.find_elements_by_css_selector("p")
    items = len(title)
    with open('btc_gmail.csv','a',encoding="utf-8") as s:
        for i in range(items):
            s.write(str(title[i].text) + ',' + link[i].text + ',' + description[i].text[30:70] + '\n')

Any Solution?


You can get text of the tag and then use slice on string

>>> description = driver.find_elements_by_css_selector("p")[0].text 
>>> print(description[30:70])  # printed from 30th to 70th symbol
'satrader03<strong>@gmail.com</strong>'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM