【发布时间】:2019-07-14 08:56:38
【问题描述】:
我正在尝试在 amazon.com 的搜索框中添加一些价值。 我使用的是请求而不是硒(按键选项)。 我已经确定了搜索框的 xpath,现在想在其中推送值,即:char“a”或“apple”或任何其他字符串,然后收集结果。 但是,当使用 post 方法推送数据以进行请求时,出现错误。 下面是我的代码:
import requests
from lxml import html
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)''AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'}
page = requests.get('https://www.amazon.com/', headers=headers)
page = requests.get('https://www.amazon.com/', headers=headers)
response_code = page.status_code
if response_code == 200:
htmlText = page.text
tree = html.fromstring(page.content)
search_box = tree.xpath('//input[@id="twotabsearchtextbox"]')
pushing_keys = requests.post(search_box,'a')
print(search_box)
但是我得到了这个错误代码:
requests.exceptions.MissingSchema: Invalid URL "[<InputElement 20b94374a98 name='field-keywords' type='text'>]": No schema supplied. Perhaps you meant http://[<InputElement 20b94374a98 name='field-keywords' type='text'>]?
如何通过请求正确推送搜索框中的任何字符? 谢谢
【问题讨论】:
-
首先了解更改该搜索框的约定(特定端点)。目前上述方法没有意义
标签: python web-scraping request lxml