【问题标题】:Parsing web-page with search bar使用搜索栏解析网页
【发布时间】:2022-07-06 02:22:37
【问题描述】:

我需要从 https://www.comicshoplocator.com/StoreLocator 解析商店名称 (<div class="LocationName">)。 问题是——当您在搜索中输入邮政编码(例如 73533)时,它不会出现在 URL 中。 因为那个 python 看不到页面上的元素。 这是我的代码 sn-p。因此,我没有收到任何输出。

如何让 python 看到带有邮政编码的输入? 谢谢

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup

browser = webdriver.Firefox(executable_path=r'C:\Geckodriver\Geckodriver.exe')
browser.get('https://www.comicshoplocator.com/StoreLocator')
browser.find_element(By.NAME, 'query').send_keys('73533' + Keys.RETURN)

html = browser.page_source
soup = BeautifulSoup(html, features="html.parser")
for tag in soup.find_all('div', class_="LocationName"):
    print(tag.text)

【问题讨论】:

    标签: python selenium parsing url beautifulsoup


    【解决方案1】:

    这段代码对我有用:

    listings = browser.find_elements(By.CLASS_NAME, 'CslsLocationItem')
    for listing in listings:
        print(listing.find_element(By.CLASS_NAME,'LocationName').get_attribute('innerText'))
    

    【讨论】:

      猜你喜欢
      • 2013-02-09
      • 2021-04-11
      • 1970-01-01
      • 2014-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-22
      相关资源
      最近更新 更多