首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用BeautifulSoup提交按钮/展开aria-expandable

使用BeautifulSoup提交按钮/展开aria-expandable
EN

Stack Overflow用户
提问于 2021-01-24 10:01:54
回答 2查看 149关注 0票数 0

您好,我正在尝试扩展此page上的按钮,以使用漂亮的汤捕获剩余的属性。这是我尝试按下的按钮的html:

代码语言:javascript
复制
<button class="button__373c0__3lYgT secondary__373c0__1bsQo" aria-expanded="false" aria-controls="expander-link-content-cf6b4b45-8720-4627-96f8-397a766b8ddb" type="submit" value="submit" style="--mousedown-x:30px; --mousedown-y:27.625px; --button-width:113.422px;"><div class=" button-content__373c0__1QNtB border-color--default__373c0__3-ifU"><span class=" text__373c0__2Kxyz button-content-text__373c0__Z-7FO text-color--inherit__373c0__1lczC text-align--center__373c0__3VrfZ text-weight--semibold__373c0__2l0fe text-size--large__373c0__3t60B text--truncated__373c0__3sLaf"><p class=" text__373c0__2Kxyz text-color--normal__373c0__3xep9 text-align--left__373c0__2XGa- text-weight--semibold__373c0__2l0fe text-size--large__373c0__3t60B">15 More Attributes</p></span></div></button>

这就是我到目前为止所得到的:

代码语言:javascript
复制
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9'}
url = 'https://www.yelp.com/biz/lazi-cow-davis?osq=lazi+cow'
response = requests.get(url, headers=headers)

sub_response = requests.get(sub_url, headers=headers)
sub_soup = BeautifulSoup(sub_response.content, 'lxml')

for item in sub_soup.select('section'):
    if item.find('h4'):
       name = item.find('h4').get_text()
       if name == "Amenities and More":
          tests = item.find_all('span')
          for span in tests:
              print(span.get_text())

我知道你可以使用Yelp API来抓取,但我需要使用+1000个不同的yelp站点,所以我想知道是否有解决办法,因为我目前的方法工作(我稍后会添加代理),只是不是所有的属性

EN

回答 2

Stack Overflow用户

发布于 2021-01-25 07:03:11

BeautifulSoup主要用于网络抓取,不能再多用了。

如果你需要与网页交互,比如点击按钮、滚动等,你需要使用浏览器。Selenium将为您提供帮助

票数 0
EN

Stack Overflow用户

发布于 2021-01-25 20:04:17

您可以尝试使用Selenium:

代码语言:javascript
复制
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Chrome('/Users/Downloads/chromedriver')

driver.implicitly_wait(30)

driver.find_element_by_xpath("//button[@class='button__373c0__3lYgT secondary__373c0__1bsQo activated__373c0__1moG8 ']").click()

for x in driver.find_elements_by_xpath("//div[@class=' arrange__373c0__2C9bH gutter-2__373c0__1DiLQ vertical-align-baseline__373c0__3HGi9 border-color--default__373c0__3-ifU']"):
    print(x.text)

告诉我这有没有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65866489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档