Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'NoneType' object has no attribute 'attrs' #1108

Open
Chido2001 opened this issue Jun 26, 2024 · 0 comments
Open

'NoneType' object has no attribute 'attrs' #1108

Chido2001 opened this issue Jun 26, 2024 · 0 comments

Comments

@Chido2001
Copy link

Chido2001 commented Jun 26, 2024

I ran the code on Collab, after starting, a notification was sent to my FB account, while on the command promt show that the login approval needed. After I approved the log in, it still run till this error message show up:

_AttributeError Traceback (most recent call last)
in <cell line: 26>()
24 # Make sure you provide the correct credentials and the correct login URL
25 # response = scraper.get("https://m.facebook.com/login/") # Use mobile login URL, no need to get this page before login
---> 26 scraper.login(email="***", password="***") # Log in first
27
28 # Now try to access the page after logging in

1 frames
/usr/local/lib/python3.10/dist-packages/facebook_scraper/facebook_scraper.py in submit_form(self, response, extra_data)
949
950 def submit_form(self, response, extra_data={}):
--> 951 action = response.html.find("form", first=True).attrs.get('action')
952 url = utils.urljoin(self.base_url, action)
953 elems = response.html.find("input[name][value]")

AttributeError: 'NoneType' object has no attribute 'attrs'_

This is the code, I've removed my personal infor:

_from facebook_scraper import FacebookScraper, utils, get_group_info
from facebook_scraper.constants import FB_MOBILE_BASE_URL

class FacebookScraper(FacebookScraper):
def get_groups_by_search(self, word: str, **kwargs):
group_search_url = utils.urljoin(FB_MOBILE_BASE_URL, f"search/groups/?q={word}")
r = self.get(group_search_url)
for group_element in r.html.find('div[role="button"]'):
button_id = group_element.attrs["id"]
group_id = find_group_id(button_id, r.text)
yield get_group_info(group_id)

def find_group_id(button_id, raw_html):
s = raw_html[raw_html.rfind(button_id) :]
group_id = s[s.find("result_id:") :].split(",")[0].split(":")[1]
return int(group_id)

scraper = FacebookScraper()

scraper.login(email="", password="") # Log in first

keyword = "Ban Nha"
group_urls = []

for group_info in scraper.get_groups_by_search(keyword): # Now that you're logged in, this should work
group_url = f"https://www.facebook.com/groups/{group_info['id']}"
group_urls.append(group_url)

print(group_urls)_

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant