2
Bir web sayfasından href bağlantılarının ve başlıklarının bir listesini ayrıştırdım. "[$]" Kelimesine sahip olmayan tüm bağlantıları tıklamak istiyorum. İşte benim kodum. Belirli bir sözcüğü olmayan çıktıdan href bağlantılarından birine nasıl tıklanır?
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import webbrowser
from selenium import webdriver
import urllib.request
import time
from bs4 import BeautifulSoup
import re
browser = webdriver.Chrome(r"C:\Users\vasanth\Downloads\Compressed\chromedriver.exe")
browser.get("http://englishworldwide.ning.com/events/event/listUpcoming")
tip = browser.page_source
soup = BeautifulSoup(tip, 'html.parser')
link = soup.find_all('div', {'class': "wrap xg_lightborder"})
for dept in link:
lilly = dept.find_all('ul', {'class': 'clist'})
for h3 in lilly:
sill = h3.find_all('li')
for sec in sill:
tap = sec.find_all('div', {'class': 'tb'})
for lip in tap:
tappy = lip.find_all('h3')
for lips in tappy:
tom = lips.find_all('a')
for pos, lee in enumerate(tom):
sappy = lee.get('href')
result = re.sub(r'<.*?>', "", str(lee))
print(result)
print(sappy)
İşte benim çıkıştır. Ve başlığında "[$]" kelimesine sahip olmayan tüm bağlantıları tıklamak istiyorum. çıkış kodu 0
DÜZENLEME 1 ile tamamladı
C:\Users\vasanth\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/vasanth/PycharmProjects/Youtube/jill.py
LEWWWP's round the clock Google+ Hangout Club!
http://englishworldwide.ning.com/events/lewwwp-s-24-7-google-hangout-club
Weekly Wednesday LEWWWP Site Text Chat
http://englishworldwide.ning.com/events/weekly-wednesday-lewwwp-site-text-chat-952
Improve your speaking fluency [$] faster-paced
http://englishworldwide.ning.com/events/improve-your-speaking-fluency-faster-paced-45
Exam Prep speaking practice [$] Answer, Discuss, Repeat
http://englishworldwide.ning.com/events/exam-prep-speaking-practice-answer-discuss-repeat-29
Transcription/Pronunciation class [SLOWER-paced/Novice level]
http://englishworldwide.ning.com/events/transcription-pronunciation-class-395
Süreci: İçinde "[$]" yok bu bağlantıları bulmak için başka adım önde bulduk. Ama bu bağlantıları kendi pozisyonlarına göre açamıyorum. Ancak aşağıdaki yöntem bu belirli bağlantıları açmaz. Ben Python kullanıyorum
s = "This be a string"
if s.find("$") == -1:
print "$ not found"
else:
print "Found $ in string"
: Burada
bağlantı dolar işareti içeriyorsa –Python'daki eşdeğer sözdizimi, myString'de değil "$" ise; – Kevin