2

我正在尝试从动态网页中提取内容。我的要求是为这把特定椅子选择座椅样式,然后从网页的表格中提取值。我使用了以下代码。输出如下所示:

import mechanicalsoup

browser = mechanicalsoup.Browser()
browse_page = browser.get('http://catalog.atsfurniture.com/9-grid-back-wood-chair.aspx')
browse_form = browse_page.soup.select("option",{"value":"Select Seat Style"})

browse_form.find(attrs={"option": "Select Seat Style"})['value'] = 'Solid Wood Seat'
#browse_form.find(attrs={"name": "password"})['value'] = 'password'

page2 = browser.submit(browse_form, browse_url)
print(str(page2.text))

输出:

TypeError                                 Traceback (most recent call last)
<ipython-input-7-4872094ff9a8> in <module>()
      3 browser = mechanicalsoup.Browser()
      4 browse_page = browser.get('http://catalog.atsfurniture.com/9-grid-back-wood-chair.aspx')
----> 5 browse_form = browse_page.soup.select("option",{"value":"Select Seat Style"})
      6 
      7 browse_form.find(attrs={"option": "Select Seat Style"})['value'] = 'Solid Wood Seat'

C:\Users\Santosh\Anaconda3\lib\site-packages\bs4\element.py in select(self, selector, _candidate_generator, limit)
   1516                     print("    Running candidate generator on %s %s" % (
   1517                         tag.name, repr(tag.attrs)))
-> 1518                 for candidate in _use_candidate_generator(tag):
   1519                     if not isinstance(candidate, Tag):
   1520                         continue

TypeError: 'dict' object is not callable

不相关的代码被注释掉。

有没有可能的解决方案。

谢谢。

4

0 回答 0