2016-03-29 14 views
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" 

cevap

0

Sadece at ... benim kod kalanı. :)
+0

: Burada

bağlantı dolar işareti içeriyorsa
tricky = BeautifulSoup(str(tom), 'html.parser') href_links = lambda tag: (getattr(tag, 'name', None) == 'a' and not '$' in tag.get_text()) for pos, final in enumerate(tricky.find_all(href_links)): simmpy = final.get('href') print(simmpy) if pos == 2: webbrowser.open(simmpy) else: break 

+0

Python'daki eşdeğer sözdizimi, myString'de değil "$" ise; – Kevin

İlgili konular