我正在尝试获取脚本来抓取一个站点,只查找具有的HREF。php?id=我可以使用bs4打印所有HREF,但无法从.php?id=中选择一个并打印它们
<li><a href="#">Education & Research </a>
<ul>
<li><a href="caseofthe_month.php">Case of the Month</a></li>
<a href="page.php?id=2">
<a href="idontwantthispagetoshowup.php">
<a href="page.php?id=5">Prospectus Fellowship-July-14</a>
<a href="thisoneeither.php">
'''
def gethref(ip):
url = ("http://" + ip)
print("[x] ~ SCAN: " + url + " ~ [x]")
req = requests.get(url)
tree = html.fromstring(req.text)
tree_href = tree.xpath('//@href')
#print(tree_href)
if '*.php?id=*' in tree_href:
print (tree_href)
#soup = BeautifulSoup(req.text, 'html.parser')
#h = soup.find_all('href=*.php')
#print(h)
#sqli = soup.select('a')
#for link in soup.find_all('a'):
# sqli = (link.get('href'))
# sqli = str(sqli)
# print(sqli)
# if 'page' in sqli:
# print(sqli.a)
您可以使用CSS选择器
a[href*=".php?id="]
:印刷品:
或:
或:
这是查找包含
.php?id=
的所有HREF所需的代码我想这就是你需要的
告诉我如果它不起作用
相关问题 更多 >
编程相关推荐