我正在编写一个脚本,它从文件中读取域列表,并检查域是否是WordPress站点。
当我试图使用有关表单控件的机械库时,我遇到了一些错误,在搜索web之后,我无法找到任何类似的解决方案。
使用的代码(如果如下所示):
br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders = [("User-agent","Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13")]
base_url = br.open("http://www.isitwp.com/")
with open('domains') as f:
for line in f:
rowdict['website'] = str(line)
br.select_form(nr=0)
br['q'] = str(line)
isitwp_response = br.submit()
isitwp_response = isitwp_response.read()
if "Good news everyone" in a:
rowdict['iswordpresswebsite'] = "yes"
else:
rowdict['iswordpresswebsite'] = "no"这些错误如下:
File "./wp_checker.py", line 26, in <module>
br['q'] = str(line)
File "/usr/local/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 796, in __setitem__
self.form[name] = val
File "/usr/local/lib/python2.7/dist-packages/mechanize/_form_controls.py", line 1956, in __setitem__
control = self.find_control(name)
File "/usr/local/lib/python2.7/dist-packages/mechanize/_form_controls.py", line 2348, in find_control
return self._find_control(name, type, kind, id, label, predicate, nr)
File "/usr/local/lib/python2.7/dist-packages/mechanize/_form_controls.py", line 2441, in _find_control
raise ControlNotFoundError("no control matching " + description)
mechanize._form_controls.ControlNotFoundError: no control matching name 'q'发布于 2019-02-05 12:04:36
在python部分看到了这一点,所以我使用了请求而不是机械化。
没有什么要解释的,代码是不言而喻的。
import requests
url = "https://www.isitwp.com/wp-admin/admin-ajax.php"
with open("domains.txt", "r+") as file: #change domains.txt to whatever your text file is named
domains = file.read().splitlines()
file.close()
def iswp(query):
data = {
"_ajax_nonce":"f7442b97c8", #you can get it from the website, just do CRTL+F and search for "nonce"
"action":"get_result",
"dataType":"json",
"q":query,
"recapt":""
}
r = requests.post(url, data=data).json()
if (r["data"]["iswp"] == 0):
print("{0} is not powered wordpress".format(query))
else:
print("{0} is powered by wordpress".format(query))
for domain in domains:
iswp(domain)https://stackoverflow.com/questions/54519575
复制相似问题