繁体   English   中英

如何使用 Python 在 Selenium 中刮取特定字符

[英]How To Scrape Specific Chracter in Selenium using Python

我想在这个 HTML 代码中刮掉 70 个字符:

<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>

我想知道如何用 selenium 刮掉特定字符,例如我想刮掉 30 个字符或其他

这是我的代码:

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')

怎么刮30个字或者70个什么的


编辑(完整代码):

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')

任何解决方案?


您可以获取标签的文本,然后在字符串上使用切片

>>> 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>'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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