python - 使用 scrapy 选择单选按钮

标签 python scrapy

我如何使用 scrapy 选择单选按钮?

我正在尝试选择以下内容

formdata={'rd1':'E'} does not work

<input type="radio" name="rd1" value="E" checked="checked" />Employee
<input type="radio" name="rd2" value="o" />Other

最佳答案

您可以使用lxml.cssselector选择单选按钮。

>>> import lxml.html
>>> from lxml.cssselect import CSSSelector
>>> str = """
... '<input type="radio" name="rd1" value="E" checked="checked" />Employee
... <input type="radio" name="rd2" value="o" />Other'
... """
>>> input_sel = CSSSelector('input[name="rd1"]')
>>> lx = lxml.html.fromstring(str)
>>> input_sel(lx)
[<InputElement b7e7665c name='rd1' type='radio'>]

关于python - 使用 scrapy 选择单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5086616/

相关文章:

python - 当带有子图的图形从 python3.2 中的 matplotlib 保存为 pdf 时创建的空 pdf

python - 如何用plotly绘制or-tools的中间解

python - 避免 scrapy 上的重复值

python - 是否可以在 heroku 上运行 scrapy?

python - 针对本地文件的 Scrapy shell

javascript - 使用 Scrapy 获取 JavaScript 函数的参数

python - Scrapy 抓取下一页。正确的规则语法

python - 正确训练 Stacked Autoencoder

python - `QTextEdit` 光标在覆盖其 `dropEvent` 后卡住

javascript - 使用 django 过滤器和带有 Angular 表达式的标签