我正在尝试使用javascript抓取网站。用户选择状态后输入脚本,然后在搜索字段中输入任何文本。我用硒来模仿它,它工作正常。 我想我可以解析浏览器并从div标签中删除数据,因为它现在在源代码中,但它不起作用。 我相信我应该使用selenium的执行函数。 以下是我到目前为止的情况:
import urllib
import urllib.request
from bs4 import BeautifulSoup
import re
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
url = "http://findrealtors.org/"
driver = webdriver.Chrome()
driver.get(url)
select = driver.find_element_by_css_selector('#selst').click()
driver.find_element_by_css_selector('#selst > option:nth-child(2)').click()
name = driver.find_element_by_css_selector('#sbmreq')
name.send_keys('a')
form = driver.find_element_by_css_selector('body > div.uk-vertical-align.uk-text-center.uk-height-1-1 > div > form > div:nth-child(4) > a').click()
moreinfo = driver.page_source
soup = BeautifulSoup(moreinfo, "html.parser")
for next in soup.findAll('div',{"class":"tt-dataset tt-dataset-typeahead"}):
print(next)
try:
for agents in next.find('div',{"class":"tt-suggestion tt-selectable"}):
print(agents)
except:
print("not found")