Issue
When I type the full name of the place I want, the result comes up, but when I leave it with *, it does not find any results and I think it gives an error. Do you have any solution suggestions? I would be glad if you explain with an example. thanks in advance for your time
import requests
from bs4 import BeautifulSoup
import re
import wget
res = requests.post("https://store.rg-adguard.net/api/GetFiles", "type=CategoryId&url=7d949c6e-f0df-4325-b022-9e031ff18885&ring=WIS&lang=en-US", headers={
"content-type": "application/x-www-form-urlencoded"
})
html = BeautifulSoup(res.content, "lxml")
a = html.find("a", string=re.compile(
"54406Simizfo\.WSATools*\.msixbundle"))
# 54406Simizfo.WSATools_0.1.56.0_neutral_~_f0x555vvp18ze.msixbundle
link = a["href"]
print(link)
Output
Traceback (most recent call last):
File "filename.py", line 12, in <module>
link = a["href"]
TypeError: 'NoneType' object is not subscriptable
Solution
When using * in regex you have to encapsulate the expression. Use:
"54406Simizfo\.WSATools(.)*\.msixbundle"
instead of just
"54406Simizfo\.WSATools*\.msixbundle"
(.) will match a single charachter. (.)* will match any number of charachters.
Answered By - areobe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.