我編寫了此代碼以登錄到我的FB帳戶,並使用Selenuim和BeautifulSoup獲取頁面上的所有組鏈接,但BeautifulSoup用法無法正常工作。使用Beautifulsoup和Selen從某個網頁獲取鏈接
我想知道如何在相同的代碼中使用Selenuim和BeautifulSoup。
我不想使用Facebook API;我想使用Selenium和BeautifulSoup。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import httplib2
from BeautifulSoup import BeautifulSoup, SoupStrainer
usr = raw_input('--> ')
pwd = raw_input('--> ')
poo = raw_input('--> ')
driver = webdriver.Firefox()
# or you can use Chrome(executable_path="/usr/bin/chromedriver")
driver.get("https://www.facebook.com/groups/?category=membership")
assert "Facebook" in driver.title
elem = driver.find_element_by_id("email")
elem.send_keys(usr)
elem = driver.find_element_by_id("pass")
elem.send_keys(pwd)
elem.send_keys(Keys.RETURN)
scheight = .1
while scheight < 9.9:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight/%s);" % scheight)
scheight += .01
soup = BeautifulSoup(html)
http = httplib2.Http()
status, response = ('https://www.facebook.com/groups/?category=membership')
count = 0
for link in BeautifulSoup(response, parseOnlyThese=SoupStrainer('a')):
count = count + 1
print 'Count: ', count
for tag in BeautifulSoup(('a')):
if link.has_key('href'):
if '/groups/' in link['href']:
print link['href']
elem = driver.find_element_by_css_selector(".input.textInput")
elem.send_keys(poo)
elem = driver.find_element_by_css_selector(".selected")
elem.send_keys(Keys.RETURN)
elem.click()
time.sleep(5)
鏈接,您需要澄清。 「*美麗的湯不適合工作*」的含義是什麼? - 發生了什麼,這與預期的行爲有什麼不同? – Celeo 2015-03-18 20:51:52
的resualt回溯(最近通話最後一個): 文件 「tk.py」 28行,在 湯= BeautifulSoup(HTML) NameError:名字 'HTML' 沒有定義 –
elsharkawey
2015-03-18 20:53:21